sonarjs/no-require-or-define
eslint-plugin-sonarjs
No autofix
eslint.config.js
export default [
{
rules: {
"sonarjs/no-require-or-define": "error",
},
},
];"import" should be used to include external code
// circle.js
exports.area = function (r) {
return PI * r * r;
};
// foo.js
define(["./cart", "./horse"], function(cart, horse) { // Noncompliant
// ...
});
// bar.js
const circle = require('./circle.js'); // Noncompliant// circle.js
let area = function (r) {
return PI * r * r;
}
export default area;
// foo.js
import cart from "./cart.js";
import horse from "./horse.js";
// bar.js
import circle from "./circle.js"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-require-or-define
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/no-require-or-define": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Increment (++) and decrement (--) operators should not be used in a method call or mixed with other operators in an expression