Files
simplify-code/rules/rust/complexity.yml
T
Giancarmine SalucciandClaude Opus 4.8 8324dde1a2 fix(rules): make magic-number detection far less noisy
Real-world test on a 321-file TS/Svelte monorepo flagged 454 magic-number
findings, ~82% of them noise: literals already assigned to a named const/field
and numbers merely buried under a binary expression (e.g. a call arg inside a
string concat). Tighten all 5 languages to: (1) require the literal be a DIRECT
operand of a binary/comparison expression, and (2) exclude initializers of a
named binding (const/var/let/field). Cuts magic-number ~67% with no loss on
fixtures (each language still detects its genuine `x > 5000` case).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-23 01:32:33 +02:00

41 lines
1.0 KiB
YAML

# Rust — complexity smells (detection only, no `fix:` → Track B / semantic).
# Note: Rust conditionals are `if_expression`.
id: rs-deep-nesting
language: Rust
severity: warning
message: "Deeply nested conditional (>=3 levels) — consider early returns / let-else."
rule:
kind: if_expression
inside:
kind: if_expression
stopBy: end
inside:
kind: if_expression
stopBy: end
---
id: rs-long-param-list
language: Rust
severity: warning
message: "Long parameter list (>=5) — consider a struct parameter."
rule:
kind: parameters
has:
kind: parameter
nthChild: 5
---
id: rs-magic-number
language: Rust
severity: info
message: "Magic number in an expression — consider a named constant."
rule:
all:
- kind: integer_literal
- not: { regex: "^(0|1|2|10|100|1000)$" }
- inside: { kind: binary_expression }
# Skip literals already named via `let`/`const`/`static` declaration.
- not: { inside: { kind: let_declaration, stopBy: end } }
- not: { inside: { kind: const_item, stopBy: end } }