Skip to main content

no-func-assign

NOTE: this rule is part of the recommended rule set.
Enable full set in deno.json:
{
  "lint": {
    "tags": ["recommended"]
  }
}
Enable full set using the Deno CLI:
deno lint --tags=recommended

Disallows the overwriting/reassignment of an existing function.

Javascript allows for the reassignment of a function definition. This is generally a mistake on the developers part, or poor coding practice as code readability and maintainability will suffer.

Invalid:

function foo() {}
foo = bar;

const a = function baz() {
  baz = "now I'm a string";
};

myFunc = existingFunc;
function myFunc() {}

Valid:

function foo() {}
const someVar = foo;

const a = function baz() {
  const someStr = "now I'm a string";
};

const anotherFuncRef = existingFunc;

let myFuncVar = function () {};
myFuncVar = bar; // variable reassignment, not function re-declaration

Did you find what you needed?

Privacy policy