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>
39 lines
976 B
YAML
39 lines
976 B
YAML
# Java — complexity smells (detection only, no `fix:` → Track B / semantic).
|
|
|
|
id: java-deep-nesting
|
|
language: Java
|
|
severity: warning
|
|
message: "Deeply nested conditional (>=3 levels) — consider guard clauses / extract method."
|
|
rule:
|
|
kind: if_statement
|
|
inside:
|
|
kind: if_statement
|
|
stopBy: end
|
|
inside:
|
|
kind: if_statement
|
|
stopBy: end
|
|
|
|
---
|
|
id: java-long-param-list
|
|
language: Java
|
|
severity: warning
|
|
message: "Long parameter list (>=5) — consider a parameter object."
|
|
rule:
|
|
kind: formal_parameters
|
|
has:
|
|
kind: formal_parameter
|
|
nthChild: 5
|
|
|
|
---
|
|
id: java-magic-number
|
|
language: Java
|
|
severity: info
|
|
message: "Magic number in an expression — consider a named constant."
|
|
rule:
|
|
all:
|
|
- kind: decimal_integer_literal
|
|
- not: { regex: "^(0|1|2|10|100|1000)$" }
|
|
- inside: { kind: binary_expression }
|
|
# Skip literals already named via field/variable declaration.
|
|
- not: { inside: { kind: variable_declarator, stopBy: end } }
|