-
Notifications
You must be signed in to change notification settings - Fork 280
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
[CompilerGenerated] not honored #931
Comments
There are 2 code analysis tools on VS right now, the Roslyn based, and the legacy one. The one you are referring to on "Project Properties > Code Analysis > Suppress results from generated code (managed only)" applies to the legacy one, which runs when you go the Analyze menu, and select to run a code analysis. We cannot control what happens there. But we do have our own way to ignore generated code. We haven't been looking at the |
Related discussions in roslyn:
@giggio You have been involved in some of the discussions there. What is your understanding of the current state in roslyn? Should we wait for the roslyn team to figure this out or should we improve on our own logic? The PR mentioned introduces the required API to ignore generated code: AnalysisContext.ConfigureGeneratedCodeAnalysis /// <summary>
/// Flags to configure mode of generated code analysis.
/// </summary>
[Flags]
public enum GeneratedCodeAnalysisFlags
{
/// <summary>
/// Disable analyzer action callbacks and diagnostic reporting for generated code.
/// Analyzer driver will not make callbacks into the analyzer for entities (source files, symbols, etc.) that it classifies as generated code.
/// Additionally, any diagnostic reported by the analyzer with location in generated code will not be reported.
/// </summary>
None = 0x00,
/// <summary>
/// Enable analyzer action callbacks for generated code.
/// Analyzer driver will make callbacks into the analyzer for all entities (source files, symbols, etc.) in the compilation, including generated code.
/// </summary>
Analyze = 0x01,
/// <summary>
/// Enable reporting diagnostics on generated code.
/// Analyzer driver will not suppress any analyzer diagnostic based on whether or not it's location is in generated code.
/// </summary>
ReportDiagnostics = 0x02,
} |
The |
I just checked and adding: context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); To the initialize method works to supress the analyzer on generated code. Only on the Now we need to check how far does the Roslyn support for generated code goes. Maybe we are doing something extra that they are not. But, where we can, we should switch to theirs and remove ours. |
@KristianWedberg @giggio Currently Roslyn does consider code marked with this attribute as generated code. However, you should not rely on this behavior in the long run because it has a substantial negative performance impact on the build and I'm working to make ignoring this attribute standard practice (the default wouldn't change, but I would encourage users to disable the setting at their earliest convenience). See dotnet/roslyn#20498. @giggio You are correct that you must opt-in to having reports suppressed in generated code. The alternative would have been a breaking change for shipped, stable analyzers that implemented and documented their own exclusion policies. |
@sharwell If I understand correctly, you are suggesting that we do not use Roslyn's feature to disable the analysis on generated code. Is my understanding correct? |
@giggio We switched StyleCop Analyzers over to Roslyn's generated code analysis for the 1.1.0-beta001 release many months ago and haven't had problems. My recommendation was actually for end users to try and avoid depending on |
Bug or Enhancement
With v1.0.3 the following generates warnings CC0091 and CC0021:
Despite
Expected
Anything (classes etc.) tagged with [CompilerGenerated] should be excluded from code analysis if
"Project Properties > Code Analysis > Suppress results from generated code (managed only)" is enabled. This is described here:
https://docs.microsoft.com/en-gb/visualstudio/code-quality/how-to-suppress-code-analysis-warnings-for-generated-code
The text was updated successfully, but these errors were encountered: