# new-operator-misuse

Rule `sonarjs/new-operator-misuse`. "new" should only be used with functions and classes

- Source: sonarjs
- Technologies: JavaScript
- Kind: correctness
- Needs type information: yes
- Autofix: no
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1237 by reach, #538 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/new-operator-misuse` | yes | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-2999/) |

## Code examples

### Incorrect: the rule reports this

```js
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
```

### Correct: the rule accepts this

```js
/**
 * @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 value
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
export default [
  {
    rules: {
      "sonarjs/new-operator-misuse": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [SonarJS recommended](https://lintradar.dev/presets/sonarjs-recommended.md) | ESLint | `eslint-plugin-sonarjs` | 230 | 6.2M | +62.1% |

## Related rules

- [sonarjs/misplaced-loop-counter](https://lintradar.dev/rules/sonarjs/misplaced-loop-counter.md): "for" loop increment clauses should modify the loops' counters
- [sonarjs/no-all-duplicated-branches](https://lintradar.dev/rules/sonarjs/no-all-duplicated-branches.md): All branches in a conditional structure should not have exactly the same implementation
- [sonarjs/memoize-cache-key](https://lintradar.dev/rules/sonarjs/memoize-cache-key.md): Lodash and Underscore.js `memoize` calls on functions with multiple parameters should use an explicit cache key function
- [sonarjs/no-alphabetical-sort](https://lintradar.dev/rules/sonarjs/no-alphabetical-sort.md): "Array.prototype.sort()" and "Array.prototype.toSorted()" should use a compare function
- [sonarjs/max-switch-cases](https://lintradar.dev/rules/sonarjs/max-switch-cases.md): "switch" statements should not have too many "case" clauses
- [sonarjs/no-angular-bypass-sanitization](https://lintradar.dev/rules/sonarjs/no-angular-bypass-sanitization.md): Angular built-in sanitization should not be disabled

---

Web page: https://lintradar.dev/rules/sonarjs/new-operator-misuse. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
