Skip to content

Commit e324ee5

Browse files
committed
fix: correct dead englishIndicators check for inline comments
The preceding-text check was dead code since match.index points to the start of 'as', so preceding text can never end with 'as soon' etc. Now checks the first word of the match itself against a list of common English words to distinguish natural language from type assertions. Adds inline comment test case to false-positives fixture.
1 parent 3c24150 commit e324ee5

3 files changed

Lines changed: 13 additions & 10 deletions

File tree

ai-slop-detector.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -752,12 +752,12 @@ class AISlopDetector {
752752
if (fullLine.startsWith('//') || fullLine.startsWith('*') || fullLine.startsWith('/*')) {
753753
continue;
754754
}
755-
// Skip matches where the preceding token is a preposition or common English word
755+
// Skip matches where the first word after "as" is a common English word
756756
// indicating natural language rather than a type assertion
757-
const matchStart = match.index ?? 0;
758-
const preceding = line.substring(Math.max(0, matchStart - 10), matchStart).trim();
759-
const englishIndicators = ['as soon', 'as quick', 'as fast', 'as smooth', 'as long', 'as much', 'as little', 'as well', 'as good', 'as bad', 'as easy', 'as hard', 'as simple', 'as clear'];
760-
if (englishIndicators.some(phrase => preceding.toLowerCase().endsWith(phrase))) {
757+
// e.g., "as soon as React hydrates" — "soon" is English, not a type
758+
const firstWord = match[0].match(/^as\s+(\w+)/i)?.[1]?.toLowerCase();
759+
const englishWords = ['soon', 'quick', 'quickly', 'fast', 'smooth', 'long', 'much', 'little', 'well', 'good', 'bad', 'easy', 'hard', 'simple', 'clear', 'many', 'few', 'close', 'far', 'near'];
760+
if (firstWord && englishWords.includes(firstWord)) {
761761
continue;
762762
}
763763
}

karpeslop-bin.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -624,12 +624,12 @@ class AISlopDetector {
624624
if (fullLine.startsWith('//') || fullLine.startsWith('*') || fullLine.startsWith('/*')) {
625625
continue;
626626
}
627-
// Skip matches where the preceding token is a preposition or common English word
627+
// Skip matches where the first word after "as" is a common English word
628628
// indicating natural language rather than a type assertion
629-
const matchStart = match.index ?? 0;
630-
const preceding = line.substring(Math.max(0, matchStart - 10), matchStart).trim();
631-
const englishIndicators = ['as soon', 'as quick', 'as fast', 'as smooth', 'as long', 'as much', 'as little', 'as well', 'as good', 'as bad', 'as easy', 'as hard', 'as simple', 'as clear'];
632-
if (englishIndicators.some(phrase => preceding.toLowerCase().endsWith(phrase))) {
629+
// e.g., "as soon as React hydrates" — "soon" is English, not a type
630+
const firstWord = match[0].match(/^as\s+(\w+)/i)?.[1]?.toLowerCase();
631+
const englishWords = ['soon', 'quick', 'quickly', 'fast', 'smooth', 'long', 'much', 'little', 'well', 'good', 'bad', 'easy', 'hard', 'simple', 'clear', 'many', 'few', 'close', 'far', 'near'];
632+
if (firstWord && englishWords.includes(firstWord)) {
633633
continue;
634634
}
635635
}

tests/fixtures/false-positives.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ async function claimTruck(truckId: string) {
125125
// Process the data as quickly as possible
126126
// Run the animation as smooth as desired
127127

128+
// Inline comment variant — should NOT trigger unsafe_double_type_assertion
129+
const msg = getMsg(); // as soon as React hydrates
130+
128131
// ============================================================
129132
// Issue #2b: console.log with conditional guards
130133
// ============================================================

0 commit comments

Comments
 (0)