sonarjs/declarations-in-global-scope
eslint-plugin-sonarjs
No autofix
eslint.config.js
export default [
{
rules: {
"sonarjs/declarations-in-global-scope": "error",
},
},
];Variables and functions should not be declared in the global scope
var myVar = 42; // Noncompliant
function myFunc() { } // Noncompliantwindow.myVar = 42;
window.myFunc = function() { };let myVar = 42;
let myFunc = function() { }// IIFE
(function() {
var myVar = 42;
function myFunc() { }
})();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/declarations-in-global-scope
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/declarations-in-global-scope": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Cyclomatic Complexity of functions should not be too high
Destructuring syntax should be used for assignments
"if ... else if" constructs should end with "else" clauses