Linter · Rules
no-func-assign
Disallow assigning to the name of a function declaration
Assigning to the name of a function declaration replaces the function for every caller from then on. It's almost always a mistake, like a typo or a variable that happens to have the same name as a function in the file.
The name of a function expression, such as retry in const run = function retry() {}, is checked too.
This rule is on by default in JavaScript files. It's off in TypeScript files, where TypeScript reports the same mistake.
Configure
On by default as an error. To turn it off:
bunfig.toml
[lint.rules]
"no-func-assign" = "off" # or "warn"
Examples
Reported:
function format(value) {
return String(value);
}
format = value => value.toFixed(2);
const run = function retry() {
retry = null;
};
Not reported:
let format = function (value) {
return String(value);
};
format = value => value.toFixed(2);
A parameter or a local variable with the same name is a different variable:
function total(items) {
let total = 0;
for (const item of items) {
total += item.price;
}
return total;
}