Add MA0194 to merge repeated is-pattern checks#1107
Merged
Conversation
Introduce MA0194 with analyzer and fixer to merge repeated is-pattern checks on the same expression into combined patterns where valid. Add focused tests and regenerate rule documentation and generated rule tables/configuration. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Set MA0194 to be enabled by default at suggestion severity and add a rule metadata test. Regenerate documentation and default editorconfig outputs to reflect the new default. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Apr 29, 2026
Open
This was referenced May 1, 2026
Open
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.
Why
Pattern checks like
value is A || value is Bare harder to read and maintain than a single combined pattern. This change adds a dedicated rule to encourage the more idiomatic C# pattern-combinator form when both checks target the same value.What changed
MA0194(MergeIsPatternChecks) inRuleIdentifiers.MergeIsPatternChecksAnalyzerto detect mergeable logical chains ofischecks on the same expression.MergeIsPatternChecksFixerto rewrite mergeable chains into combinedor/and/notpatterns while preserving precedence.MergeIsPatternChecksAnalyzerTestscovering:||merges&&merges includingnotdocs/Rules/MA0194.mdand regenerated generated documentation/config files (README.md,docs/README.md, and pack editorconfig files).Notes for reviewers
&&chains of only positive constant patterns (for examplevalue is A && value is B), the rule still reports, but the code fix intentionally does not merge that specific case because the directandrewrite is rejected by the compiler (CS8518).