sonarjs/no-for-in-iterable
eslint-plugin-sonarjs
No autofix
eslint.config.js
export default [
{
rules: {
"sonarjs/no-for-in-iterable": "error",
},
},
];"for in" should not be used with iterables
const arr = [4, 3, 2, 1];
for (let value in arr) { // Noncompliant
console.log(value); // logs 0, 1, 2, 3
}const arr = [4, 3, 2, 1];
for (let value of arr) {
console.log(value);
}Examples from the ESLint documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
sonarjs/no-for-in-iterable
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/no-for-in-iterable": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Function declarations should not be made within blocks