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

Prefer readonly struct analyzer and codefix #657

Merged
merged 5 commits into from
Aug 19, 2024

Conversation

danigutsch
Copy link
Contributor

PR Classification

New feature to enforce the use of readonly structs in C# code. #603

PR Summary

Introduces a new code fix provider and analyzer to ensure structs are marked as readonly when appropriate.

  • MakeStructReadonlyCodeFixProvider.cs: Added a new CodeFixProvider to apply the readonly modifier to structs.
  • AnalyzerReleases.Unshipped.md: Added rule entry VOG033 for the new analyzer.
  • RuleIdentifiers.cs: Added constant UseReadonlyStructInsteadOfStruct for rule VOG033.
  • PreferReadonlyStructAnalyzer.cs: Added a new DiagnosticAnalyzer to report diagnostics for non-readonly structs.
  • PreferReadonlyStructsAnalyzerTests.cs: Added tests to verify the analyzer's behavior.

Introduced a new analyzer class `PreferReadonlyStructAnalyzer` to enforce the use of `readonly struct`. Applys to `struct` and `record struct`
Introduce a new code fix provider class `MakeStructReadonlyCodeFixProvider` to automatically make structs readonly when the diagnostic created by `PreferReadonlyStructAnalyzer` is triggered.
Added a new rule to the `AnalyzerReleases.Unshipped.md` file:
- **Rule ID**: VOG033
- **Category**: Usage
- **Severity**: Info
- **Notes**: UseReadonlyStructInsteadOfStructAnalyzer
@SteveDunn SteveDunn self-requested a review August 19, 2024 17:48
Copy link
Owner

@SteveDunn SteveDunn left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks very much for your contribution!

@SteveDunn SteveDunn merged commit 986f494 into SteveDunn:main Aug 19, 2024
6 checks passed
@danigutsch danigutsch deleted the prefer-readonly-struct branch August 19, 2024 19:33
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.

2 participants