* 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.
// 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: [],
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);
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) {