2 * @fileoverview Rule to flag use of function declaration identifiers as variables.
3 * @author Ian Christian Myers
8 const astUtils = require("./utils/ast-utils");
10 //------------------------------------------------------------------------------
12 //------------------------------------------------------------------------------
19 description: "disallow reassigning `function` declarations",
20 category: "Possible Errors",
22 url: "https://eslint.org/docs/rules/no-func-assign"
31 * Reports a reference if is non initializer and writable.
32 * @param {References} references Collection of reference to check.
35 function checkReference(references) {
36 astUtils.getModifyingReferences(references).forEach(reference => {
37 context.report({ node: reference.identifier, message: "'{{name}}' is a function.", data: { name: reference.identifier.name } });
42 * Finds and reports references that are non initializer and writable.
43 * @param {Variable} variable A variable to check.
46 function checkVariable(variable) {
47 if (variable.defs[0].type === "FunctionName") {
48 checkReference(variable.references);
53 * Checks parameters of a given function node.
54 * @param {ASTNode} node A function node to check.
57 function checkForFunction(node) {
58 context.getDeclaredVariables(node).forEach(checkVariable);
62 FunctionDeclaration: checkForFunction,
63 FunctionExpression: checkForFunction