Is there a way to sync settings from Settings.StyleCop to ReSharper? - c#

My question is quite simple: Is there a way to sync the changes you make in the Settings.StyleCop file into the ReSharper settings?
As it is now I have to first make the changes in Settings.StyleCop (so that StyleCop can validate my code using the rules I want) and then I have to make the same changes in ReSharper to get syntax highlighting and warnings in code as i type.
I found this question but it doesn't seem to apply anymore. ReSharper doesn't read StyleCop.Settings.

With the StyleCop (4.7.44.0) plugin for R#:
Under the R# options, Tools, StyleCop section:

Related

Export Resharper code style settings into Editor.Config

I am trying to create a single place for code-style and formatting rules for our solution.
We are currently using Resharper, which stores this info in the {slnName}.dotSettings file. However, some developers don't want to use Resharper due to its performance issues. So they don't get these rules and warnings.
EditorConfig seemed like a suitable replacement, but I wanted to translate the ReSharper rules (where possible) into editor config rules and also include all the ReSharper specific rules so that those who do use ReSharper get the extra rules too, and they are all stored in one place (One source of truth!).
Anyway, trying to grasp what the .dotSettings file is doing has been unfruitful, and I know that Resharper will read in editor config files, so I'd like it to export it too
With Resharper 2019.1 you can now 'Export settings to .editorconfig'. The option lives in Resharper -> Tools.
This will export the standard editor config options, the Visual Studio specific config options and the resharper specific configs. Very useful!
In Reshaper 2019.3, this option is found in "Resharper Options | Code Editing | General Formatter Style"
As described here -> https://blog.jetbrains.com/dotnet/2019/03/28/export-editorconfig-code-style-optimize-references-sdk-projects-resharper-2019-1-eap-updates/

Is add_imports_to_deepest_scope setting in .editorconfig the same as AddImportsToDeepestScope setting in .DotSettings?

When I set add_imports_to_deepest_scope=true:error in my .editorconfig file, it has no effect (Resharper still puts using directives outside of a namespace). I made sure that Resharper is aware of my .editorconfig and also that .editorconfig overrides Resharper's settings.
When I set AddImportsToDeepestScope to true in Resharper settings, however, it starts to do what I want.
The add_imports_to_deepest_scope setting is listed on the Resharper website, so I assume it should work the same. Am I wrong?
The setting in question is a ReSharper setting, and ReSharper settings currently do not allow mixing inspection severities (like error or warning) with setting values. Besides, there are currently no inspections in ReSharper that check the placement of using directives. So please simply write "true" instead of "true:error".

ReSharper: Fix across solution

Below I have added a screenshot to explain the issue. I am trying to fix certain warnings across solution, not just in a single file. It's really hard to fix them across solution when you're editing an old project with 1,000+ files and you've got 1000+ warnings that could simply be fixed in a matter of minutes, but I've been juggling with them for days.
Is there a way to enable ReSharper option to fix across solution? Or fix across folder even. This happens with a lot of issues, "Remove redundant initializer", "Remove case 0", and "Convert body to LINQ"
You can change the Resharper settings from Resharper Options menu.
Go to :
Resharper --> Options --> Code Inspection --> Inspection Severity.
Choose C# or VB.Net as per your project language then find "Language Usage Opportunities" and change the settings for "Convert body to LINQ" from 'Warning' to 'Hint'.
Your other problems are also can be fix in similar manner.

Disable stylecop analysis for specific projects within solution

Is there a way to easily stop StyleCop warnings from being displayed within specific projects in a solution. Or, more pointedly, a way to select which projects StyleCop analysis should be performed on by Visual Studio?
We have a solution with 9 projects in it. There are only 2 projects that I actually want to see StyleCop warnings for, so I've created StyleCop.Settings files within those project root directories. This means that, for the rest of the projects, the default rule set is applied and I get a screen full of warnings every time I open a class.
The only way I can think to remove these warnings is to add another StyleCop.Settings file a folder level above with all the rules switched off and set merge options on the specific Settings files I am interested in to not merge with this parent file. This just feels wrong though. Is there a cleaner option or is this my only one?
UPDATE: I'm specifically looking for a way to stop the warnings from appearing within Visual Studio. I've added a Settings.StyleCop file to the solution folder and disabled all the rules. I run StyleCop analysis across one of my test projects and there are no errors reported. However, opening a test class reveals a raft of StyleCop warnings, which I want to suppress. Could this be the StyleCop for ReSharper plugin? I have a code cleanup profile created and have disabled certain rules within there but that doesn't appear to make any difference within my test classes.
Please have a look at File Lists configuration - they allow to disable rules by default per project:
Enabled Or Disabled By Default
In addition, a new setting allows you to determine whether rules
should be enabled or disabled by default. This can be set either at
the project level or at the SourceFileList level. For example, here’s
how you would set up a project with all rules disabled by default, and
only two rules explicitly enabled:
<StyleCopSettings Version="4.3">
<GlobalSettings>
<BooleanProperty Name="RulesEnabledByDefault">False</BooleanProperty>
</GlobalSettings>

how to Import fxcop file to stylecop

I have one .fxcop rule file is there any way where i can import this file to Stylecop?
Please let me know the step by step approach for this.
Thanks...
Don't think that's possible as FxCop and StyleCop are completely different tools for different purposes. See Stylecop vs FXcop
Depending on the rule you have in FxCop, it might be possible to port it to StyleCop (or Roslyn), but you can's simply import or combine these tools. The reason behind this is that FxCop inspects the compiled binaries, while StyleCop parses the actual source code.
If you update your question to include the purpose of the rule, we might be able help you with that.

Categories

Resources