Is safe to combine VS and R# Code CleanUp?

Hello to all,

I would like to apply code fixes on save, but I cannot find a way to configure the code cleanup for this. I'm wondering if it is safe to combine both VS and R# code cleanup. I once experienced an infinite loop by doing this which I solved by cleaning all fixes in the VS profile and then by manually adding only the required ones. My main concern is that in future R# releases the same fix could be added to the R# cleanup profile and this could result in the previous mentioned problem if it is already present in the VS profile. Does R# has a mechanism to prevent such conflicts?

I also saw in the SDK  a BulkCodeCleanupActionBuilderBase.CreateProfile(). Does this allows to create a customized cleanup profile with all the code fixes exposed?

0
4 comments

Hello dshaggtun luzzi, thank you for your question.

apply code fixes on save, but I cannot find a way to configure the code cleanup for this

Please try to do the following:

- open "ReSharper | Options | Code Editing | Code Cleanup | Profiles";

- select which Code Cleanup profile should be applied on save;

- make a duplicate of one of the profiles;

- configure everything you need in it;

- click Set as default;

- save changes.

Does R# has a mechanism to prevent such conflicts?

No, I don't think so. Could you please describe how you combine both VS and R# code cleanup?

0

Many thanks for your help.

I tried your suggestion, but without success. I created the profile copy and I can see it in GlobalSettingsStorage.DotSettings. However, when I try to insert custom values, nothing happens.

For example, I'm trying to add "Inline out variable declaration quick-fix":

int toLine;
if (int.TryParse("222", out toInline))
Debug.WriteLine(toInline)

I temporarely disabled the warning to get the key name of the fix:

// ReSharper disable once InlineOutVariableDeclaration

Then, inside DotSettings custom profile section, I insert InlineOutVariableDeclaration="True", but nothing happens when I save the file and the custom fix is not even listed in the UI. I tried to place it in different locations (escaped and unescaped), but without any result.

I didn't thought to the most obvious thing: a copied profile should remains the same across all R# versions and I can at least avoid R# and VS trying to fight to apply the same fix.

This is how I combined both VS and R# code cleanup.

"Text Editor > code cleanup > Run code cleanup on save", then I configured the list of fixes like this:

Styles are configured like this (you can see the same inline variable fix I tried to run through R#):

I carefully selected only the fixes that are not already included in R# profile and it seems to work fine.

However it would be much better if I could leave all the cleanup job to R# instead of involving VS too.

Thanks

0

Hello dshaggtun luzzi, thanks for the reply.

Unfortunately, "Inline out variable declaration" quick fix cannot be applied when using code cleanup. Here is a feature request about it.

All settings that are used during code cleanup can be edited in "ReSharper | Options | Code Editing | Code Cleanup | Profiles". 

Just in case, I would like to note that this is not correct line: InlineOutVariableDeclaration="True". The correct one for DotSettings file is the following:

<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=InlineOutVariableDeclaration/@EntryIndexedValue">WARNING</s:String>

The settings value here is the severity of the issue. Please let me know if you have any questions.

0

Thanks for your response. I must have misunderstood. In other words, the only fixes that can be applied are the ones listed in the preconfigured profiles. Therefore, combining both VS and R# cleanup is the only way to run fixes not supported by R#.

Thanks

1

Please sign in to leave a comment.