ErrorProne.NET
ErrorProne.NET copied to clipboard
Violations show up on generated code
We've started to use the generated HTTP clients that uses NSwag to generate a typed client, and EPS01 "Struct 'ObjectResponseResult' can be made readonly" is showing up on the generated code. Is it intentional that ErrorProne.NET doesn't ignore generated code? I think usually generated code is excluded, but it looks like this project opts in to that. I think this line enabled that for the given analyzer, and was added by @sharwell, so I'm looping him also him. Maybe, he can shine some light on this decision.
Repro
Just add ErrorProne.NET.Structs, and add a connected service. This is how I managed to get it reproduced in a new project:
- Create a new console project
- Add the ErrorProne.NET.Structs package
- Add a connected service according to the blog post, I've used the
petstore.json
example from the OpenAPI repo - Build the project, to ensure that the
petstoreClient.cs
file is generated
This should result in EPS01
: "Struct 'ObjectResponseResult' can be made readonly" @petstoreClient.cs:256
I think this line enabled that for the given analyzer, and was added by @sharwell, so I'm looping him also him. Maybe, he can shine some light on this decision.
My change was to make the current behavior explicit instead of implicit (generated code is included by default if ConfigureGeneratedCodeAnalysis
is not called). Someone will need to consider the overall application impact if these change.
Note that EPS01 may be a candidate for a global suppression approach, especially for cases where the type is public
or the assembly has any IVTs. The warning indicates a potentially suboptimal exposed API, and in this context the generated code status has no impact.
@sharwell Thanks for the feedback, I didn't consider the implicit/explicit change, makes sense :) I understand, making such a decision is not yours to take, when you do a change like you did in #168, but rather of the maintainer.
@SergeyTeplyakov Is changing the generated code analysis mode something to consider, or do you rather want to keep it this way?
@sharwell Thanks for the suggestion, we did added a suppression in the .editorconfig
for EPS01, but then rather for the generated file itself, by adding a section [petstoreClient.cs]
(but then named for our actual client, obviously), as we still wanted to keep the violation enabled for non-generated code.
Stale