Skip to content

Disable code analysis for generated code#10337

Merged
harshit7962 merged 1 commit into
dotnet:mainfrom
ThomasGoulet73:disable-code-analysis-for-generated-code
Feb 11, 2025
Merged

Disable code analysis for generated code#10337
harshit7962 merged 1 commit into
dotnet:mainfrom
ThomasGoulet73:disable-code-analysis-for-generated-code

Conversation

@ThomasGoulet73
Copy link
Copy Markdown
Contributor

@ThomasGoulet73 ThomasGoulet73 commented Jan 26, 2025

Description

Disables code analysis for generated code. Code analysis for generated code does not make sense since generated code will never be perfectly formatted and it prevents doing auto formatting to generated code without modifying the code generator.

We'll probably want to format the generated code someday but it should probably be done only when #6135 is merged and we can modify the code generator instead of modifying the generated code manually.

Customer Impact

None.

Regression

No.

Testing

Local build + CI.

Risk

None.

Microsoft Reviewers: Open in CodeFlow

@ThomasGoulet73 ThomasGoulet73 requested review from a team as code owners January 26, 2025 21:35
@dotnet-policy-service dotnet-policy-service Bot added PR metadata: Label to tag PRs, to facilitate with triage Community Contribution A label for all community Contributions labels Jan 26, 2025
@dipeshmsft
Copy link
Copy Markdown
Member

Even when we have enabled MilCodeGen, we would still need to keep some rules disabled for the generated code right ? Like the rule for unnecessary imports, is something that needs to be disabled in that case.

/cc @harshit7962

@ThomasGoulet73
Copy link
Copy Markdown
Contributor Author

The typical behavior of code analyzers is to ignore generated files, code analysis uses a specifc pattern to detect generated files and the files generated by MilCodeGen does not match that pattern. This PR makes it so that code analysis knows that MilCodeGen files are generated.

Personally I don't see much value in enabling code analysis for generated files. Generated code will probably never be perfect and IMO it should be done manually (By removing the line I added locally and manually checking the warnings).

@harshit7962 harshit7962 self-assigned this Feb 11, 2025
Copy link
Copy Markdown
Member

@harshit7962 harshit7962 left a comment

Choose a reason for hiding this comment

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

LGTM, as suggested we can take care of styling in generated code later.

@harshit7962 harshit7962 merged commit e987ae4 into dotnet:main Feb 11, 2025
@harshit7962
Copy link
Copy Markdown
Member

Thank you for the contribution @ThomasGoulet73.

@ThomasGoulet73
Copy link
Copy Markdown
Contributor Author

Thanks @harshit7962

@ThomasGoulet73 ThomasGoulet73 deleted the disable-code-analysis-for-generated-code branch February 11, 2025 23:33
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Community Contribution A label for all community Contributions PR metadata: Label to tag PRs, to facilitate with triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants