-
Notifications
You must be signed in to change notification settings - Fork 511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] Is it possible to setup StyleCop analyzers from .editorconfig file? #3045
Comments
Support for this was added in #3285 |
You can configure enabling or disabling of rules and the severity of StyleCop analyzer warnings in the editor config. At least this works well in visual studio. |
If so, how exactly? I tried last month adding eg. StyleCop.SA1508.severity = information and it did not worked. Its not clear under which name rules are accessible, plus other rules names are always in lower case with underscores. https://github.com/RehanSaeed/EditorConfig/blob/master/.editorconfig - in this example there is few rules mentioned and it works with installed nuget of stylecop but for other I havent found any determinable naming convention between stated rule names in config file and source code here. |
@JadaVonRuth You only need to click on the light bulb and in If you have an The naming convention is valid for every analyzers and is pretty The rules in the file you linked are the rules built into Visual Studio and you need to go in |
@leoniDEV I thought dotnet_diagnostic.RULE_CODE.severity works only with built in analyzers, so i did not even try and after all it works for any analyzer, Perfect!. Thanks very much for clarifying that! I wrote some analyzers of my own, wanted to combine them with stylecop and I could not work out how to configure them in editorconfig since using assembly name was not working and official microsoft did not stated that anywhere when describing how to write analyzers. The rest I am familiar with. |
I can take this one ✋ I'll see what I can whip up later this weekend 🙂 |
@mikernet Thanks, let me know if you have any questions about the new APIs for this ( |
I'm starting to familiarize myself with the code and formulating an approach but I have a couple of questions:
|
I'm not sure it matters since having the options in both places will not be a common scenario. If one option performs better than the other, we should use that. Otherwise, we'll pick one for convenience and document it. |
@mikernet Did you have any luck trying this? @sharwell At the moment we need to have the options in two places, the entries in .editorconfig are used by VS and the entry in stylecop.json for stylecop and they can be contradicting or have different defaults if not listed. This is the case for those settings that have entries defined in either file: @mavasani are there plans to make the code from Analyzer.Utilities.Options from the roslyn analyzers available to 3rd party analyzers like StyleCop and NUnitAnalyzers? including the aggregation of file added to 3.3. It would remove duplication in |
@manfred-brands Been trying to get input from @sharwell as to what an acceptable approach would be for this but it hasn't gone anywhere 🤷♂️ It's going to be a good chunk of work so I'm not going to rewrite the entire option system without some kind of nod of approval indicating the PR will be accepted given the approach. |
For those who don't use Visual Studio, I made a simple converter to generate the .editorconfig settings from the .ruleset file. Maybe it will be useful for those who use VSCode. https://github.com/RempelOliveira/SA-RulesetToEditorConfig |
@RempelOliveira A closer equivalent to .ruleset is .globalconfig (both of these formats apply to all inputs to a compilation, where .editorconfig only applies to files under a specific directory). Also, it is now possible to define all values from stylecop.json in either of these files. |
If you put the .editorconfig file at the root of the repository, it will work for all files lower in the hierarchy. Regardless, just change the file extension to .globalconfig if you prefer, the intention of what I've shared is just to convert the .ruleset rules to .editorconfig or .globalconfig rules format for those who don't use Visual Studio and don't have this feature of simple form. See the example below:
|
In case it helps others... I'm finding that in vscode, after stylecop rules are added or changed in the .editorconfig file., a "Reload Window" is required in order for the rules to get picked up. This seems to be the case across different code analysis packages (not a stylecop issue). |
Hello,
Is it possible to setup StyleCop analyzers with a .editorconfig file? Replacing the stylecop.json file?
Or is there any tool to have the same rules configured the same way in both files?
Regards
The text was updated successfully, but these errors were encountered: