Skip to main content

js/noFunctionAssign

disallow reassigning function declarations

ESLint Equivalent: no-func-assign

Examples

Invalid

function foo() {}; foo = bar;

 file.ts:1:19 lint/js/noFunctionAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Do not reassign a function declaration.

    function foo() {}; foo = bar;
                       ^^^

  Use a local variable instead.


function foo() { foo = bar; }

 file.ts:1:17 lint/js/noFunctionAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Do not reassign a function declaration.

    function foo() { foo = bar; }
                     ^^^

  Use a local variable instead.


foo = bar; function foo() { };

 file.ts:1 lint/js/noFunctionAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Do not reassign a function declaration.

    foo = bar; function foo() { };
    ^^^

  Use a local variable instead.


[foo] = bar; function foo() { };

 file.ts:1:1 lint/js/noFunctionAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Do not reassign a function declaration.

    [foo] = bar; function foo() { };
     ^^^

  Use a local variable instead.


({x: foo = 0} = bar); function foo() { };

 file.ts:1:5 lint/js/noFunctionAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Do not reassign a function declaration.

    ({x: foo = 0} = bar); function foo() { };
         ^^^

  Use a local variable instead.


function foo() { [foo] = bar; }

 file.ts:1:18 lint/js/noFunctionAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Do not reassign a function declaration.

    function foo() { [foo] = bar; }
                      ^^^

  Use a local variable instead.


(function() { ({x: foo = 0} = bar); function foo() { }; })();

 file.ts:1:19 lint/js/noFunctionAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Do not reassign a function declaration.

    (function() { ({x: foo = 0} = bar); function foo() { }; })();
                       ^^^

  Use a local variable instead.

Valid

function foo() { var foo = bar; }
function foo(foo) { foo = bar; }
function foo() { var foo; foo = bar; }
var foo = () => {}; foo = bar;
var foo = function() {}; foo = bar;
var foo = function() { foo = bar; };
import bar from 'bar'; function foo() { var foo = bar; }