Disallow function declarations that contain unsafe references inside loop statements.
This rule applies only to .js and .ts files.
const a = function(): void {
console.info('hello');
};
for (let i = 10; i; i--) {
a();
}
for (let i = 10; i; i--) {
const b = function(): void {
a();
}; // OK, no references to variables in the outer scopes.
b();
} const num = 10;
for (let i = num; i; i--) {
// Variable i is an unsafe reference.
(function(): number {
return i;
})();
}
let i1 = 0;
while (i1 < num) {
// Variable i is an unsafe reference.
const a = function(): number {
return i1;
};
a();
i1++;
}
let i2 = 0;
do {
// Variable i is an unsafe reference.
function a(): number {
return i2;
}
a();
i2++;
} while (i2 < num); plugin:@typescript-eslint/all
For details about how to configure Code Linter check rules, see Code Linter.