no-func-assign

Disallow assigning to the name of a function declaration

error by default

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#

example.js1 problem
function format(value) {
  return String(value);
}

format = value => value.toFixed(2);
example.js1 problem
const run = function retry() {
  retry = null;
};
example.jsNo problems
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:

example.jsNo problems
function total(items) {
  let total = 0;
  for (const item of items) {
    total += item.price;
  }
  return total;
}