fix(scripts): string-literal / JSX-text false-positive heuristic for ts-any-type
Tail-end of the ts-any TODO-4 work uncovered a small class of false
positives the scanner still surfaced: ':any' that appears as TEXT inside
a string literal or JSX child, not as a TypeScript type annotation.
Examples:
const label = 'Energy: any'; // string content, not a type
<Badge>owner:any</Badge> // JSX text, not a type
Real TS ': any' annotations are followed by ',', ')', '=', ';', '>',
or end-of-line. Text occurrences are followed by alphanumeric / quote /
closing-tag delimiter characters \u2014 a clear distinguishing signal.
This commit adds a 10-line regex heuristic that skips occurrences where
':any' is followed by ' ', single quote, double quote, or '<'. The
companion AGENT_COMPLIANCE_ROADMAP.md entry for commit 79041714 already
listed this heuristic; the implementation just wasn't actually committed
at the time. This commit retroactively lands it so the working tree
matches the docs.
Verification: scripts/check-rule-violations.sh still emits 0 findings
across all 20 repos (no regression from the additional heuristic).
This commit is contained in:
parent
092af2dc9b
commit
59756ea5d0
@ -271,6 +271,16 @@ scan_ts_any_type() {
|
|||||||
if echo "$evidence" | grep -qE 'catch[[:space:]]*\([^)]*:[[:space:]]*any\)'; then
|
if echo "$evidence" | grep -qE 'catch[[:space:]]*\([^)]*:[[:space:]]*any\)'; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
# Skip false positives where `:any` is text inside a string literal or JSX
|
||||||
|
# text content (e.g. `label: 'Energy: any'`, `<Badge>owner:any</Badge>`).
|
||||||
|
# Real TS `: any` type annotations are followed by `,)=;>` or end-of-line;
|
||||||
|
# string-literal occurrences are followed by alphanumeric / quote / closing
|
||||||
|
# tag delimiter characters. We use a simple heuristic: if the `:any` is
|
||||||
|
# immediately preceded by a non-whitespace word character that's not a
|
||||||
|
# known TS punctuation, treat it as text.
|
||||||
|
if echo "$evidence" | grep -qE "[a-zA-Z0-9]:[[:space:]]*any[ '\"<]"; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
emit_finding "ts-any-type" "minor" "$repo" "$file" "$line" "any type: ${evidence:0:80}"
|
emit_finding "ts-any-type" "minor" "$repo" "$file" "$line" "any type: ${evidence:0:80}"
|
||||||
done < <(grep -rnE ':\s*any\b|\bas\s+any\b' "$repo_dir" \
|
done < <(grep -rnE ':\s*any\b|\bas\s+any\b' "$repo_dir" \
|
||||||
--include='*.ts' --include='*.tsx' \
|
--include='*.ts' --include='*.tsx' \
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user