The same name is declared twice with var in one function
What it finds
var lets the same name be declared again in a function without complaint, and both declarations then name one variable. The second one reads as a fresh variable but may receive the value left by the first, which hides mistakes when code is copied or moved.
Every var declaration of a name after the first in the same function or file is reported. Declarations with let, const and class cannot be repeated at all, which the parser or compiler reports.
From the rule's source, var_redeclared.rs.
export function loops(items: number[]) { for (var i = 0; i < items.length; i++) {} for (var i = 0; i < 3; i++) {}tx0 reports: i is already declared with var var total = 0; return total + i;} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/ts:var-redeclared" = "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:var-redeclared] reason="..."tx0 explain tx0/ts:var-redeclared shows the same in the terminal. Found a false positive? Report it.