The name of a function or class declaration is assigned another value
What it finds
function handler() {} ... handler = null; or class Cache {} ... Cache = new Map();: assigning to the name of a function or class declaration replaces it for all code that runs afterwards. Declarations read as fixed, and such an assignment is usually a mix-up with a variable of a similar name.
Wrapping a function on purpose, as fn = memoize(fn), is written this way too, which is why the rule is recommended rather than on by default; a variable for the wrapped function says the same without the surprise.
From the rule's source, declaration_reassign.rs.
function handler() { return 1;}class Cache {}function reset() { handler = () => 2;tx0 reports: handler names a function declaration Cache = class {};tx0 reports: Cache names a class declaration let local = handler; local = () => 3; return local;} 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:declaration-reassign" = "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:declaration-reassign] reason="..."tx0 explain tx0/ts:declaration-reassign shows the same in the terminal. Found a false positive? Report it.