# 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.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

On by default as an error. To turn it off:

```toml bunfig.toml
[lint.rules]
"no-func-assign" = "off" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```js
function format(value) {
  return String(value);
}

format = value => value.toFixed(2);
```

{/* bad */}
```js
const run = function retry() {
  retry = null;
};
```

Not reported:

{/* good */}
```js
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:

{/* good */}
```js
function total(items) {
  let total = 0;
  for (const item of items) {
    total += item.price;
  }
  return total;
}
```
