chore(lint): justify intentional no-control-regex (ANSI strip) + ratchet to error (#737)
The 5 no-control-regex warnings are all the same intentional ANSI-color-strip pattern /\x1b\[[0-9;]*m/g across 5 test files. The \x1b (ESC) control char is the required leading byte of an ANSI SGR sequence, so matching it is the whole point of stripping color codes from captured CLI/console output. Add an inline eslint-disable-next-line with justification at each site (not a refactor — the control char is essential, not accidental), then flip no-control-regex from warn to error so the debt can't regrow. Refs #736 Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -222,7 +222,7 @@ export default tseslint.config(
|
||||
// Downgraded from recommended error → warn (pre-existing violations; follow-up to fix)
|
||||
'no-useless-escape': 'warn',
|
||||
'no-regex-spaces': 'warn',
|
||||
'no-control-regex': 'warn',
|
||||
'no-control-regex': 'error',
|
||||
'no-irregular-whitespace': 'warn',
|
||||
},
|
||||
},
|
||||
|
||||
@@ -39,6 +39,7 @@ function captureFinishInstallOutput(runtime, isGlobal) {
|
||||
console.log = original;
|
||||
}
|
||||
// Strip ANSI color escapes so message-content assertions don't couple to colors.
|
||||
// eslint-disable-next-line no-control-regex -- \x1b (ESC) is the required leading byte of ANSI SGR color sequences; matching it is the purpose of stripping ANSI codes from captured CLI/console output
|
||||
return lines.join('\n').replace(/\x1B\[[0-9;]*m/g, '');
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ const COMMANDS_DIR = path.join(ROOT, 'commands', 'gsd');
|
||||
|
||||
// Strip ANSI color codes so log assertions don't depend on TTY detection.
|
||||
function stripAnsi(s) {
|
||||
// eslint-disable-next-line no-control-regex -- \x1b (ESC) is the required leading byte of ANSI SGR color sequences; matching it is the purpose of stripping ANSI codes from captured CLI/console output
|
||||
return s.replace(/\x1b\[[0-9;]*m/g, '');
|
||||
}
|
||||
|
||||
|
||||
@@ -317,6 +317,7 @@ describe('install.js update-banner wiring', () => {
|
||||
// Strip ANSI color escapes before structural assertions — the choice
|
||||
// digits are wrapped in color codes so word-boundary regex against the
|
||||
// raw text would miss them.
|
||||
// eslint-disable-next-line no-control-regex -- \x1b (ESC) is the required leading byte of ANSI SGR color sequences; matching it is the purpose of stripping ANSI codes from captured CLI/console output
|
||||
const stripped = text.replace(/\x1b\[[0-9;]*m/g, '');
|
||||
// Prompt must offer at least two choices (default + opt-in).
|
||||
assert.match(stripped, /\b1\b/);
|
||||
|
||||
@@ -334,6 +334,7 @@ describe('context meter respects CLAUDE_CODE_AUTO_COMPACT_WINDOW (#2219)', () =>
|
||||
|
||||
// Parse normalized used% from the statusline bar output (e.g. "60%")
|
||||
// Strip ANSI escape codes then extract the percentage digit(s) before "%"
|
||||
// eslint-disable-next-line no-control-regex -- \x1b (ESC) is the required leading byte of ANSI SGR color sequences; matching it is the purpose of stripping ANSI codes from captured CLI/console output
|
||||
const clean = stdout.replace(/\x1b\[[0-9;]*m/g, '');
|
||||
const match = clean.match(/(\d+)%/);
|
||||
const normalizedUsed = match ? parseInt(match[1], 10) : null;
|
||||
|
||||
@@ -133,6 +133,7 @@ function withSdkDistPresent(fn) {
|
||||
}
|
||||
|
||||
function stripAnsi(value) {
|
||||
// eslint-disable-next-line no-control-regex -- \x1b (ESC) is the required leading byte of ANSI SGR color sequences; matching it is the purpose of stripping ANSI codes from captured CLI/console output
|
||||
return value.replace(/\x1b\[[0-9;]*m/g, '');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user