sonarjs/new-operator-misuse
eslint-plugin-sonarjs
No autofixRecommended
eslint.config.js
export default [
{
rules: {
"sonarjs/new-operator-misuse": "error",
},
},
];"new" should only be used with functions and classes
function MyClass() {
this.foo = 'bar';
}
var someClass = 1;
var obj1 = new someClass; // Noncompliant;
var obj2 = new MyClass(); // Noncompliant if considerJSDoc parameter set to true. Compliant when considerJSDoc=false/**
* @constructor
*/
function MyClass() {
this.foo = 'bar';
}
var someClass = function(){
this.prop = 1;
}
var obj1 = new someClass; // Compliant
var obj2 = new MyClass(); // Compliant regardless of considerJSDoc valueExamples from the ESLint documentation.
sonarjs/new-operator-misuse
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/new-operator-misuse": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
"for" loop increment clauses should modify the loops' counters
All branches in a conditional structure should not have exactly the same implementation
Lodash and Underscore.js memoize calls on functions with multiple parameters should use an explicit cache key function
"Array.prototype.sort()" and "Array.prototype.toSorted()" should use a compare function
"switch" statements should not have too many "case" clauses
Angular built-in sanitization should not be disabled