A variable is declared with var
What it finds
var declares a variable for the whole function, visible before its declaration and shared by every iteration of a loop; let and const declare it for the block, which is what is almost always meant.
The fix to let is safe when it cannot change what the code does: the declaration is directly in the body of a function or at the top level of a module, so its scope stays the same, every variable it declares is declared only there, and every use comes after it in the text, outside function declarations, which could be called before it. Otherwise it is offered as unsafe. Declarations in ambient contexts, declare var and those in declare global or declare module, describe globals and must stay var.
From the rule's source, no_var.rs.
var top = 1;tx0 reports: use let or const instead of var function run(items: number[]) { var total = 0;tx0 reports: use let or const instead of var for (var i = 0; i < items.length; i++) {tx0 reports: use let or const instead of var total += items[i]; } return total + top;} declare var ambient: number;declare global { var injected: string;} 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:no-var" = "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:no-var] reason="..."tx0 explain tx0/ts:no-var shows the same in the terminal. Found a false positive? Report it.