sonarjs/no-global-this
eslint-plugin-sonarjs
SuggestionRecommended
eslint.config.js
export default [
{
rules: {
"sonarjs/no-global-this": "error",
},
},
];this.foo = 1; // Noncompliant
console.log(this.foo); // Noncompliant
function MyObj() {
this.foo = 1; // Compliant
}
MyObj.func1 = function() {
if (this.foo == 1) { // Compliant
// ...
}
}foo = 1;
console.log(foo);
function MyObj() {
this.foo = 1;
}
MyObj.func1 = function() {
if (this.foo == 1) {
// ...
}
}Examples from the ESLint documentation.
sonarjs/no-global-this
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/no-global-this": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Forced browser interactions should not bypass actionability checks
Special identifiers should not be bound or assigned
Floating point numbers should not be tested for equality
Boolean expressions should not be gratuitous