SonarSource / sonar-dotnet

Code analyzer for C# and VB.NET projects
https://redirect.sonarsource.com/plugins/csharp.html
GNU Lesser General Public License v3.0
777 stars 226 forks source link

AutoGenerated: Consider using the build in `IsGenerated` properties of the analysis contexts #8298

Open martin-strecker-sonarsource opened 11 months ago

martin-strecker-sonarsource commented 11 months ago

Detecting generated code is an essential building block for our analyzers. At the moment, we use a heuristic on the syntax-tree level in the GeneratedCodeRecognizer. This has some problems:

In https://github.com/dotnet/roslyn/issues/7578 from September 2022, IsGeneratedCode was added to all ..AnalyzisContext types by the Roslyn team:

We should consider lighting up these properties and using them if the compiler supports them. We need to see how Roslyn recognizes the AutoGenerated code, how it differs from outer logic, and what to do about the differences.

Related links:

pavel-mikula-sonarsource commented 11 months ago

There's a related Trello card about this area: https://trello.com/c/Nc2mpdjz/180-read-generatedcodeanalysisflags-from-roslyn-for-generated-code-analysis

costin-zaharia-sonarsource commented 10 months ago

Related: #5461