import { CatchErrorPatternConfig } from '@webpieces/rules-config'; import type { EditContext, Violation } from '../types'; import { EditRuleBase } from '../rule-base'; import { FixHint } from '../fix-hint'; export declare class CatchErrorPatternRule extends EditRuleBase { constructor(config: CatchErrorPatternConfig); readonly description = "Catch blocks must use: catch (err: unknown) { const error = toError(err); }"; readonly files: string[]; get fixHint(): FixHint; check(ctx: EditContext): readonly Violation[]; /** * The first statement of the catch block, judged against BOTH line arrays — and that pairing is the * whole fix for a bug that made this rule refuse the exact cure it prescribes. * * The rule FINDS catch clauses in `ctx.strippedLines`, which is right: a `catch (e) {` inside a * comment is not a catch clause. But it used to also LOOK FOR the toError statement there, and * stripping deletes `//const error = toError(err);` down to an empty line — so Fix Option 2, the * documented way to say "this error is deliberately ignored", was reported as "no toError statement" * every single time. TO_ERROR_PATTERN's optional `//` prefix could never match, because nothing * carrying a `//` ever reached it. 34 catches in this repo already use that form. * * So: the RAW line decides whether the commented form is present, and the STRIPPED line decides what * counts as "the first statement" (a blank line, a `{`, or an unrelated comment is skipped past). * Raw is tested first because it is the only array in which the comment form survives; a live * statement with a trailing comment (`const error = toError(err); // why`) fails the raw test on the * `$` anchor and is then matched on its stripped form, which is exactly the intent. * * COMMENT_REMNANT is the other half of that, and it is a property of the stripper: `stripTsNoise` * KEEPS the `//` marker and blanks only what follows it, so a stripped comment line trims to `//` * rather than to the empty string. Without normalizing that away, `//` is neither blank nor a `{`, * so it was taken for the first statement — which is the mechanical reason a commented-out toError * reported "no toError statement", and the reason a trailing `// why` on a LIVE toError reported the * same. One replace fixes both, in the one place the question is asked. */ private findToErrorStatement; }