]> git.proxmox.com Git - pve-eslint.git/blobdiff - eslint/lib/rules/no-loop-func.js
import 8.41.0 source
[pve-eslint.git] / eslint / lib / rules / no-loop-func.js
index 13ebd3ee22b8d721fee98392ebe6437bc7154a2d..e1d65fdc92c1aafbd56764751fe3a489e13b669a 100644 (file)
@@ -125,7 +125,7 @@ function isSafe(loopNode, reference) {
      * The reference is every reference of the upper scope's variable we are
      * looking now.
      *
-     * It's safeafe if the reference matches one of the following condition.
+     * It's safe if the reference matches one of the following condition.
      * - is readonly.
      * - doesn't exist inside a local function and after the border.
      * @param {eslint-scope.Reference} upperRef A reference to check.
@@ -148,15 +148,15 @@ function isSafe(loopNode, reference) {
 // Rule Definition
 //------------------------------------------------------------------------------
 
+/** @type {import('../shared/types').Rule} */
 module.exports = {
     meta: {
         type: "suggestion",
 
         docs: {
-            description: "disallow function declarations that contain unsafe references inside loop statements",
-            category: "Best Practices",
+            description: "Disallow function declarations that contain unsafe references inside loop statements",
             recommended: false,
-            url: "https://eslint.org/docs/rules/no-loop-func"
+            url: "https://eslint.org/docs/latest/rules/no-loop-func"
         },
 
         schema: [],
@@ -168,13 +168,15 @@ module.exports = {
 
     create(context) {
 
+        const sourceCode = context.sourceCode;
+
         /**
          * Reports functions which match the following condition:
          *
          * - has a loop node in ancestors.
          * - has any references which refers to an unsafe variable.
          * @param {ASTNode} node The AST node to check.
-         * @returns {boolean} Whether or not the node is within a loop.
+         * @returns {void}
          */
         function checkForLoops(node) {
             const loopNode = getContainingLoopNode(node);
@@ -183,7 +185,7 @@ module.exports = {
                 return;
             }
 
-            const references = context.getScope().through;
+            const references = sourceCode.getScope(node).through;
             const unsafeRefs = references.filter(r => !isSafe(loopNode, r)).map(r => r.identifier.name);
 
             if (unsafeRefs.length > 0) {