A let, const, function or class is declared directly in a case and is visible in every other one
What it finds
case "a": const value = 1; ... case "b": value;: all the clauses of a switch share one block, so a let, const, class or function declared directly in one clause is visible in the others, where it is not initialized when their code runs, and reading it throws. The same name declared in two clauses is a syntax error.
Braces around the clause's statements give the declaration a block of its own.
From the rule's source, case_scoped_declaration.rs.
export function label(kind: string) { switch (kind) { case "a": const value = 1;tx0 reports: this declaration belongs to the whole switch return value; case "b": { const other = 2; return other; } default: return 0; }} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/ts:case-scoped-declaration" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/ts:case-scoped-declaration] reason="..."tx0 explain tx0/ts:case-scoped-declaration shows the same in the terminal. Found a false positive? Report it.