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

Mark source generator file as generated #16777

Merged
merged 2 commits into from
Apr 7, 2021

Conversation

martincostello
Copy link
Member

Give the output file for the ProvideApplicationPartFactoryAttribute a .g suffix so that it is treated as a generated file to prevent it being flagged by source analyzers for violations the application developer cannot fix themselves. See reactiveui/refit#1067 for a similar fix.

Otherwise an application using a package such as StyleCop.Analyzers can receive warnings/errors for the code emitted by the source generator as it is not determined to have been generated by tooling and to be user code.

For example, using 6.0.100-preview.3.21202.5 of the SDK errors such as the following are emitted;

C:\Coding\martincostello\api\src\API\Microsoft.NET.Sdk.Razor.SourceGenerators\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\API.UnifiedAssembly.Info.cs(1,221): error SA1518: File is required to end with a single newline character [C:\Coding\martincostello\api\src\API\API.csproj]
C:\Coding\martincostello\api\src\API\Microsoft.NET.Sdk.Razor.SourceGenerators\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\API.UnifiedAssembly.Info.cs(1,1): error SA1633: The file header is missing or not located at the top of the file. [C:\Coding\martincostello\api\src\API\API.csproj]

I wasn't sure of the best way to add a unit test for this, or how to go about validating this locally.

Give the output file for the ProvideApplicationPartFactoryAttribute a ".g" suffix so that it is treated as a generated file to prevent it being flagged by source analyzers for violations the application developer cannot fix themselves.
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@martincostello
Copy link
Member Author

/cc @captainsafia @pranavkm

Add an explicit .cs suffix.
Copy link
Member

@captainsafia captainsafia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

We've got the compiled views covered with the // <auto-generated> flag but missed this.

@pranavkm
Copy link
Contributor

pranavkm commented Apr 7, 2021

@captainsafia should we add the doc /// <auto-generated comment to this file too?

@captainsafia
Copy link
Member

@pranavkm I think that's good hygiene today. We can include that change next time we make a modification to the RSG.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants