sonarjs/block-scoped-var
eslint-plugin-sonarjs
No autofixRecommended
eslint.config.js
export default [
{
rules: {
"sonarjs/block-scoped-var": "error",
},
},
];Variables should be used in the blocks where they are declared
function doSomething(a, b) {
if (a > b) {
var x = a - b; // Noncompliant
}
if (a > 4) {
console.log(x);
}
for (var i = 0; i < m; i++) { // Noncompliant, both loops use same variable
}
for (var i = 0; i < n; i++) {
}
return a + b;
}function doSomething(a, b) {
var x;
if (a > b) {
x = a - b;
}
if (a > 4) {
console.log(x);
}
for (let i = 0; i < m; i++) {
}
for (let i = 0; i < n; i++) {
}
return a + b;
}Examples from the ESLint documentation.
sonarjs/block-scoped-var
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/block-scoped-var": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Enforce the use of variables within the scope they are defined
Bitwise operators should not be used in boolean contexts
Function call arguments should not start on new lines
Chai assertions should have only one reason to succeed
Amazon SNS topics should be encrypted at rest