Skip to content

eslint/no-func-assign Correctness ​

✅ This rule is turned on by default.

What it does ​

Disallow reassigning function declarations

Why is this bad? ​

Overwriting/reassigning a function written as a FunctionDeclaration is often indicative of a mistake or issue.

Examples ​

Examples of incorrect code for this rule:

javascript
function foo() {}
foo = bar;
javascript
function foo() {
  foo = bar;
}
javascript
let a = function hello() {
  hello = 123;
};

Examples of correct code for this rule:

javascript
let foo = function () {};
foo = bar;
javascript
function baz(baz) {
  // `baz` is shadowed.
  baz = bar;
}
function qux() {
  const qux = bar;  // `qux` is shadowed.
}

How to use ​

To enable this rule in the CLI or using the config file, you can use:

bash
oxlint --deny no-func-assign
json
{
  "rules": {
    "no-func-assign": "error"
  }
}

References ​

Released under the MIT License.