Skip to content
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

Suggestion to Include Criteria for Identifying Generated Code in AnalysisContext.ConfigureGeneratedCodeAnalysis() Documentation #74177

Open
homu-konamilk opened this issue Jun 27, 2024 · 0 comments
Assignees

Comments

@homu-konamilk
Copy link

Type of issue

Missing information

Description

Dear .NET Documentation Team,
I am writing to provide feedback on the documentation for the AnalysisContext.ConfigureGeneratedCodeAnalysis() method. Currently, the documentation states:

Configure analysis mode of generated code for this analyzer. Non-configured analyzers will default to an appropriate default mode for generated code. It is recommended for the analyzer to invoke this API with the required GeneratedCodeAnalysisFlags setting.

However, the criteria for determining whether a piece of code is considered "generated code" are not specified in the documentation.
Upon reviewing the Roslyn source code, it appears that the following criteria are used to identify generated code:
https://github.com/dotnet/roslyn/blob/9951cebdc4f5581a0a06c1355f9f8c033ba0cb70/src/Compilers/Core/Portable/SourceGeneration/GeneratedCodeUtilities.cs

  • The file name starts with any of the following strings:
    • TemporaryGeneratedFile_
  • The file name (excluding the extension) ends with any of the following strings:
    • .designer
    • .generated
    • .g
    • .g.i
  • The comment at the beginning of the file contains any of the following strings:
    • <autogenerated
    • <auto-generated

Since these criteria are not documented, it is common to encounter cases where files with names that do not meet these criteria (e.g., .gen.cs) are unintentionally subjected to analysis. I believe it would be beneficial to include these criteria in the documentation to help users avoid such issues.

Thank you for considering this suggestion.

Page URL

https://learn.microsoft.com/en-us/dotnet/api/microsoft.codeanalysis.diagnostics.analysiscontext.configuregeneratedcodeanalysis?view=roslyn-dotnet-4.7.0

Content source URL

https://github.com/dotnet/roslyn-api-docs/blob/live/dotnet/xml/Microsoft.CodeAnalysis.Diagnostics/AnalysisContext.xml

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Analyzers untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 27, 2024
@Cosifne Cosifne removed the untriaged Issues and PRs which have not yet been triaged by a lead label Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants