Repository navigation
feat: treat Rust matches! patterns as magic-string decision points - #214
Merged
Merged
Conversation
tree-sitter leaves macro arguments as flat token trees, so `matches!` string patterns never counted. The new RustPatterns module reads a `matches!` argument tree token by token: a string literal counts when its top-level item follows the first comma and precedes any `if` guard, at any nesting depth. Both parsed invocations (`matches!`, `std::matches!`) and `matches` `!` token sequences nested in another macro, such as `assert!(matches!(...))`, are recognized. Guard comparisons and other macros' arguments stay uninterpreted. The Rust case-pattern syntax moves into RustPatterns.fs so Rust.fs stays within the file-coherence function limit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Energy State Diff vs
|
| File | Base | Head | Δ | Status |
|---|---|---|---|---|
| src/Languages/Rust.fs | 0 | 0 | 0 | ⚪ unchanged |
| src/Languages/RustPatterns.fs | — | 0 | — | 🆕 new |
| tests/DetectorFixtureMatrixTests.fs | 4 | 4 | 0 | ⚪ unchanged |
3 files changed, 0 worsened, 0 improved, 1 new.
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.
Summary
Follow-up to #212. tree-sitter leaves macro arguments as flat token trees, so a string in a
matches!pattern never counted as a magic-string decision point. Code like this was missed:Each string appears once in
matches!and once in amatcharm, so it's now flagged (meets the defaultminDuplicatesof 2).How it works
src/Languages/RustPatterns.fsreads amatches!argument tree token by token:ifguard. Literals at any nesting depth inside those items count, soSome("a" | "b")counts.matches!invocation is recognized in two forms:macro_invocationnamedmatchesor with a path ending in it (std::matches!)matches!followed by an argument group, as inassert!(matches!(kind, Some("x")))Stays clean:
matches!(k, Some(v) if v == "x")), which are unparsed tokens rather than a pattern.assert_eq!(kind, "x")).The Rust case-pattern syntax moved out of
Rust.fsinto the new module, soRust.fsstays within the file-coherence function limit. The module is added to the.fsprojand the source guide.Test plan
just test: 628 passed. The Rustmagic string case patternsmatrix row now has:flagged_macro_pattern,flagged_nested_macro_patternclean_macro_guard,clean_other_macroclean_macro_patternlimitation casejust lint,just md-lintjust analyze: no new findings compared withmainmatches!/matchrepeats🤖 Generated with Claude Code