-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Exclude files or folder from running through the analyzers through a configuration file. #3705
Comments
This issue is really annoying, it prevents people from using these analyzers on WPF projects. I thought I'll add a vot to this and mention that it took me a while to get find this place, so please don't consider this something that nobody cares about. I can tell you that more than half of my team is bothered by this problem |
We want to provide a way for analyzer authors to simply say don't report issues in generated code. The diagnostic engine will have a set of heuristics that define "generated code". However we need a configuration file that users could use to define generated code, like the rules mentioned in this issue. We'll use this issue to track the need for such a configuration file. |
1. Add a new API: AnalysisContext.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags analysisMode) Configures analyzer callbacks + diagnostic reporting for the analyzer. Recommended for analyzer authors to always invoke this API. 2. Analyzer driver uses a heuristic to identify generated code: 1. Symbols marked with GeneratedCodeAttribute. 2. Files with specific extensions (see [here](http://source.roslyn.io/Microsoft.CodeAnalysis.Workspaces/R/ef3599fb042e3706.html)). 3. Files which have a single line comment starting with <auto-generated> at the beginning of a source file. 3. Driver defaults for non-configured analyzers: 1. Run analysis on generated code: This avoids semantic breaks for analyzers and will be guaranteed to be always enabled in future. 2. Report all diagnostics on generated code: This will likely be changed to perform some level of default filtering after dotnet#3705 is implemented. Fixes dotnet#6998
I am not able to exclude a class file using below code in editor config. Could anyone please help. [*.FileName.cs] |
@beninkg it will only be available in visual studio 16.5 preview 2. |
Thanks @Logerfo for the quick response. |
Any leads would be greatly appreciated! |
Now officially documented at https://docs.microsoft.com/visualstudio/code-quality/use-roslyn-analyzers?view=vs-2019#configure-generated-code |
@Logerfo did this not make it in 16.6? I'm having trouble getting it to work. When I do:
It still generates warnings, when I do:
Then warning goes away. Even I put this in:
It is supposed to remove all warnings and errors, but it doesn't. |
Compiler warnings (CSxxxx) do not respect If you feel this option should be respected for all compiler warnings, feel free to file a new issue. |
@mavasani I think the problem not only in compiler warnings: V.S. 16.6.1; Microsoft.CodeAnalysis.FxCopAnalyzers 3.0.0. |
@kirsan31 that is a security rule, and the analyzers for most security rules register analyzing and reporting diagnostics in generates code. The assumption here is that you likely don’t want to ship security vulnerabilities in generated code. |
Hi All, We have a custom roslyn analyzer with custom rules. We would like it to run on all files except a few, like, Startup.cs, Program.cs etc.,
But what I am looking for is the ability to stop all warnings/erros on these files. Is this possible? Thanks, |
@francisminu Which specific diagnostic IDs are you looking to suppress? |
These are custom rules we have developed for the different scenarios which we wanted to enforce in our development flow. So, not the microsoft ID's as such. The intent is to suppress all rules for the files Program.cs and STartUp.cs. SO not a specific id, specific id scenario works (shown above), but I want to suppress all rules, not just one. |
You can try the below: https://docs.microsoft.com/visualstudio/code-quality/use-roslyn-analyzers?view=vs-2019#set-rule-severity-of-multiple-analyzer-rules-at-once-in-an-editorconfig-file [Startup.cs]
dotnet_analyzer_diagnostic.severity = none |
That worked perfectly! Thanks Manish! Never caught my eye on this link, thanks once again :) |
@mavasani |
I personally have tried many suggestions and only found one that works, which is specifically disabling the rules for files in the obj directorie; like so: [**/obj/**.cs]
dotnet_diagnostic.CS8019.severity = none The following didn't work for me: [**/obj/**.cs]
dotnet_analyzer_diagnostic.severity = none and [**/obj/**.cs]
generated_code = true Tested with Visual Studio Code and a .NET 5.0 project. Hope this helps someone |
This is already explained in a previous comment here. CSxxxx is a compiler warning, CAxxxx is an an analyser diagnostic, thus the former is not covered by |
Hmm - when I try this, I get the following error: Can the .editorconfig coexist with ruleset files or are they mutually exclusive? |
Hello community! We had started migrating a large project with StyleCop Classic to StyleCop.Analyzers. Here are wide use of ExcludeFromStyleCop directives on large amount of files for some reasons. These files are not generated, written by engineers, and count of them is so large. So we need a solution how to exclude them from being analyzed WITHOUT marking them as generated (that's not true). We had also tried @sharwell may you pls assist me here? Recently you replied on my question in StyleCop.Analyzers repo that this behavior is Roslyn-backed and should be discussed here. |
@innomaxx This issue is already closed, can you file a new one? |
Sure, I will |
This is not working for me:
so, I use both:
|
Hi,
we have a lot of generated files that trigger warnings, errors when analyzers run them.
since the file name of the generated files do not follow the common naming conventions for generated code roslyn fires the analyzers away. As a result there are ten of thousands of warnings in the solution.
Could we get a exclude file from analyzing logic that:
Most of the rules come straight from Resharper's exclusion file manager
Thanks
The text was updated successfully, but these errors were encountered: