ErrorProne.NET icon indicating copy to clipboard operation
ErrorProne.NET copied to clipboard

Violations show up on generated code

Open tiesmaster opened this issue 3 years ago • 2 comments

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:

  1. Create a new console project
  2. Add the ErrorProne.NET.Structs package
  3. Add a connected service according to the blog post, I've used the petstore.json example from the OpenAPI repo
  4. 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

tiesmaster avatar Dec 05 '21 20:12 tiesmaster

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 avatar Dec 06 '21 17:12 sharwell

@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.

tiesmaster avatar Dec 06 '21 20:12 tiesmaster

Stale

tiesmaster avatar May 10 '23 10:05 tiesmaster