-
-
Notifications
You must be signed in to change notification settings - Fork 261
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
Roslynator seems to run on code generated by source generator and does not read editorconfig settings while doing so #876
Comments
Hi, thanks for the report and code sample. It seems that code analysis is executed on files generated with source generator. This behavior is not specific to Roslynator analyzers. If you use this code: class C
{
} in your sample project you will get following error:
The other thing I discovered is that the file path of the generated file is relative which make is incompatible with editorconfig (which requires absolute path to determine proper configuration) This can be fixed by verifying if the source file path is relative or absolute and skip these files. Current solution to this issue is to mark generated source as generated. Either set
Then the generated source will be excluded from code analysis. Another option is to disable I would be interested if Roslyn team intended to execute code analysis on source generator's files and if there is some way how to configure this behavior. |
Oh, interesting, thank you that information. I didn't know that Regarding the relative path, would it be possible to resolve the path relative to the project and check if the file exists on disk? I'm thinking maybe it wouldn't make sense to look for an editorconfig file for a virtual file. Whether the Roslyn team intended to execute code analysis on source generator's files or not I can only guess, but I can imagine it being useful occasionally, like checking for nullability issues and such rather than stylistic issues. Edit: I renamed my generated files with |
Following entry dotnet_diagnostic.ROS0003.severity = none will disable it but there are some false positives. Until it is resolved my recommendation is to suppress it: [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Roslynator", "ROS0003")] I will probably disable by default analyzers that require option to be set. Which means that by default you should not see any warnings. Another option is to disable ROS0003 by default. |
ok thanks, that's sorted it |
I have a project that references another project that has source generators, this seems to cause a bug in Roslynator v4.0.0 that makes it print incorrect warnings about missing configuration options even though they are present in the editorconfig file.
I have created a sample project that reproduces the issue:
https://github.com/DavidZidar/roslynator-analyzer-bug
Example log output:
Product and Version Used: Roslynator.Analyzers v4.0.0
Steps to Reproduce:
Actual Behavior:
Incorrect warnings are printed.
Expected Behavior:
No warnings should be printed because the configuration options are in fact present.
The text was updated successfully, but these errors were encountered: