-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Suppress warning for generated code #41171
Comments
This looks like a compiler issue. User wants to suppress specific compiler warnings in generated code, but as far as I know the compiler itself never supported a project/compilation wide setting for it in past. I believe user has 2 options, if that helps:
|
Will reply back with the two possible solutions. |
I'd be curious to know if there are any options that will suppress these warnings while compiling, and do not involve patching generated code |
Hi, I have I'm not 100% sure this is the same as what's described above. |
I think that is the inverse of what is meant here. The idea is that generated code may contain problems that you cannot fix, and you would like to suppress the errors only for the generated files, not the other way around. |
@boukeversteegh yeah, you are right. #54119 is what I am seeing |
I have a similar situation. While generating code my It would be a nice addition if users could override the |
Automatic type-registration is a new source generation feature that was added in Hot Chocolate 12.8 that removes the need to explicitly register every individual data load and type extension. Unfortunately the generated code does not include XML documentation. Since rules in standard EditorConfig files don't apply to code generated by source generators [1], the neatest solution I could think of for avoiding CS1591 (missing XML comment warnings) was to suppress the rule through a global AnalyzerConfig file [2] for the Buttercup.Web project instead of the root EditorConfig file. [1] dotnet/roslyn#41171 [2] https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/configuration-files#global-analyzerconfig
Automatic type-registration [1] is a new source generation feature added in Hot Chocolate 12.8 that removes the need to explicitly register every individual data loader and type extension. Unfortunately the generated code does not include XML documentation. Since rules in standard EditorConfig files don't apply to code generated by source generators [2], the neatest solution I could think of for avoiding CS1591 (missing XML comment warnings) was to suppress the rule through a global AnalyzerConfig file [3] for the Buttercup.Web project instead of the root EditorConfig file. [1] https://chillicream.com/blog/2023/02/08/new-in-hot-chocolate-13#type-auto-registration [2] dotnet/roslyn#41171 [3] https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/configuration-files#global-analyzerconfig
@mikadumont we've been waiting for three long years... |
CS1591 can be suppressed using the Here's an example of a diagnostic suppressor for a different scenario: |
@sharwell do you know how to supress CS0618 (member is obsolete)? Will the provided Such section in editorconfig
does not work for some reason. |
As it stands, CS1591 is behaving by design. There are two proper solutions which will remove this diagnostic:
This is by design because downstream consumers have no way to distinguish between public APIs written directly and public APIs written by a source generator. The |
@hankovich this seems to be a different situation. Can you create a new issue with a code sample for the generator which is resulting in CS0618? |
This issue has been moved from a ticket on Developer Community.
Once upon a time it was possible to suppress
CS1591:Missing XML comment for publicly visible type or member
for generated code via that properties page (Solution Explorer -> Properties -> Code Analysis Settings).How can this be established now for .net core solutions?
I have tried the following, but that does not seem to work, as it is a compiler warning and not a code analysis warning?
[assembly: SuppressMessage("Compiler", "CS1591", Justification="Generated Code", Scope="namespaceanddescendants", Target="MyNamespaceContainingGeneratedCode")]
The only option I see at the moment, is to move all generated code to a separate project and just set
<noWarn>1591</noWarn>
in the project file. A viable option, but it falls short if you want to add your own logic to some of the generatedpartial
classes.https://github.com/MicrosoftDocs/visualstudio-docs/issues/3871
Related to: #3230
Original Comments
Visual Studio Feedback System on 1/16/2020, 10:45 PM:
Thank you for taking the time to provide your suggestion. We will do some preliminary checks to make sure we can proceed further. We'll provide an update once the issue has been triaged by the product team.
The text was updated successfully, but these errors were encountered: