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

Diagnostic suppressions from editorconfig are ignored in source-generated syntax trees #52014

Closed
jcouv opened this issue Mar 20, 2021 · 2 comments
Labels
Area-Compilers New Feature - Source Generators Source Generators Resolution-By Design The behavior reported in the issue matches the current design

Comments

@jcouv
Copy link
Member

jcouv commented Mar 20, 2021

Repro:

  1. make a change to C# compiler's syntax.xml to add some new public APIs
  2. run eng\generate-compiler-code.cmd followed by build.cmd -runAnalyzers: notice RS0016 errors (public APIs must be declared)
  3. modify top-level .editorconfig file to suppress RS0016 (see diff below)
  4. repeat step 2: notice that RS0016 errors are still there

I took a quick stab at debugging. A few observations:

  • CSharpDiagnosticFilter.GetDiagnosticReport has a parameter SyntaxTreeOptionsProvider syntaxTreeOptions which maps syntax trees with diagnostic options from editorconfig, but the source-generated syntax trees are missing from the map.
  • CommonCompiler.RunCore prepares that map (local sourceFileAnalyzerConfigOptions) before we run the generators in CompileAndEmit but that map doesn't get updated to account for source-generated syntax trees

We encountered this problem here: #51299 (review)

diff --git a/.editorconfig b/.editorconfig
index 6d966e98ae2..bbff4905b81 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -204,6 +204,9 @@ csharp_style_inlined_variable_declaration = true:suggestion
 csharp_style_throw_expression = true:suggestion
 csharp_style_conditional_delegate_call = true:suggestion

+# RS0016: Add public types and members to the declared API
+dotnet_diagnostic.RS0016.severity = none
+
 # Space preferences
 csharp_space_after_cast = false
 csharp_space_after_colon_in_inheritance_clause = true
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Mar 20, 2021
@chsienki
Copy link
Contributor

@jcouv This is by-design.

.editorconfig files don't apply to generated syntax trees, beause they don't have a path on disk (they might if you specify generatedFilesOut, but its not a given).

Instead you need to use a .globalconfig to apply rules to them. We already have a global config in the repo here:https://github.com/dotnet/roslyn/blob/831dffa401f3d0ac4addbbebe14b94e4d20df14e/global.editorconfig

@jcouv
Copy link
Member Author

jcouv commented Mar 21, 2021

It's a bit surprising since the generated syntax trees do have a path (even though they are not materialized on disk).
But if that's expected, then let's close. Thanks!

@jcouv jcouv closed this as completed Mar 21, 2021
@jcouv jcouv added Resolution-By Design The behavior reported in the issue matches the current design and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Mar 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers New Feature - Source Generators Source Generators Resolution-By Design The behavior reported in the issue matches the current design
Projects
None yet
Development

No branches or pull requests

2 participants