123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- "use strict";
- const astUtils = require("./utils/ast-utils");
- module.exports = {
- meta: {
- type: "problem",
- docs: {
- description: "Disallow reassigning `function` declarations",
- recommended: true,
- url: "https://eslint.org/docs/latest/rules/no-func-assign"
- },
- schema: [],
- messages: {
- isAFunction: "'{{name}}' is a function."
- }
- },
- create(context) {
- const sourceCode = context.sourceCode;
-
- function checkReference(references) {
- astUtils.getModifyingReferences(references).forEach(reference => {
- context.report({
- node: reference.identifier,
- messageId: "isAFunction",
- data: {
- name: reference.identifier.name
- }
- });
- });
- }
-
- function checkVariable(variable) {
- if (variable.defs[0].type === "FunctionName") {
- checkReference(variable.references);
- }
- }
-
- function checkForFunction(node) {
- sourceCode.getDeclaredVariables(node).forEach(checkVariable);
- }
- return {
- FunctionDeclaration: checkForFunction,
- FunctionExpression: checkForFunction
- };
- }
- };
|