C#: Improve cs/missed-readonly-modifier and to code-quality suite.#19520
Merged
michaelnebel merged 7 commits intogithub:mainfrom May 27, 2025
Merged
C#: Improve cs/missed-readonly-modifier and to code-quality suite.#19520michaelnebel merged 7 commits intogithub:mainfrom
cs/missed-readonly-modifier and to code-quality suite.#19520michaelnebel merged 7 commits intogithub:mainfrom
Conversation
cs/missed-readonly-modifier and to code-quality suite.
36998db to
2c8fa06
Compare
2c8fa06 to
f1805b1
Compare
f1805b1 to
008d5b7
Compare
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the cs/missed-readonly-modifier query to avoid changing semantics for mutable structs, eliminates additional false positives (non-public field assignments and static-field writes in instance constructors), and integrates the query into the code-quality suite.
- Exclude mutable struct types from readonly-modifier suggestions
- Refine detection to skip non-public argument-field assignments and static-field initializations
- Add the improved query to the
code-qualitysuite and update tests
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| csharp/ql/test/query-tests/Language Abuse/MissedReadonlyOpportunity/MissedReadonlyOpportunityBad.cs | Marked the bad-case field to trigger the new alert |
| csharp/ql/test/query-tests/Language Abuse/MissedReadonlyOpportunity/MissedReadonlyOpportunity.qlref | Updated reference to include postprocessing for inline expectations |
| csharp/ql/test/query-tests/Language Abuse/MissedReadonlyOpportunity/MissedReadonlyOpportunity.expected | Added new expected alerts for Bad3, Left, and X fields |
| csharp/ql/test/query-tests/Language Abuse/MissedReadonlyOpportunity/MissedReadonlyOpportunity.cs | Extended the test scenario with mutable/immutable structs, tree and static-fields cases |
| csharp/ql/src/change-notes/2025-05-22-missed-readonly-modifier.md | Added changelog entry for the improved precision of the query |
| csharp/ql/src/Language Abuse/MissedReadonlyOpportunity.ql | Updated the main QL predicate to exclude mutable structs and refine constructor checks |
| csharp/ql/integration-tests/posix/query-suite/csharp-code-quality.qls.expected | Added MissedReadonlyOpportunity.ql to the code-quality suite |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In this PR we
cs/missed-readonly-modifier. The reason is, that it can alter the semantics of the program for mutable structs. Example can be seen herecode-qualitysuite.DCA looks good.