]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/lib/rules/no-func-assign.js
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 //------------------------------------------------------------------------------
14 /** @type {import('../shared/types').Rule} */
20 description
: "disallow reassigning `function` declarations",
22 url
: "https://eslint.org/docs/rules/no-func-assign"
28 isAFunction
: "'{{name}}' is a function."
35 * Reports a reference if is non initializer and writable.
36 * @param {References} references Collection of reference to check.
39 function checkReference(references
) {
40 astUtils
.getModifyingReferences(references
).forEach(reference
=> {
42 node
: reference
.identifier
,
43 messageId
: "isAFunction",
45 name
: reference
.identifier
.name
52 * Finds and reports references that are non initializer and writable.
53 * @param {Variable} variable A variable to check.
56 function checkVariable(variable
) {
57 if (variable
.defs
[0].type
=== "FunctionName") {
58 checkReference(variable
.references
);
63 * Checks parameters of a given function node.
64 * @param {ASTNode} node A function node to check.
67 function checkForFunction(node
) {
68 context
.getDeclaredVariables(node
).forEach(checkVariable
);
72 FunctionDeclaration
: checkForFunction
,
73 FunctionExpression
: checkForFunction