# constructor-for-side-effects

Rule `sonarjs/constructor-for-side-effects`. Objects should not be created to be dropped immediately without being used

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

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/constructor-for-side-effects` | yes | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-1848/) |

## Code examples

### Incorrect: the rule reports this

```js
new MyConstructor(); // Non-Compliant
```

### Correct: the rule accepts this

```js
var something = new MyConstructor();  // Compliant
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/constructor-for-side-effects": "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/concise-regex](https://lintradar.dev/rules/sonarjs/concise-regex.md): Regular expression quantifiers and character classes should be used concisely
- [sonarjs/content-length](https://lintradar.dev/rules/sonarjs/content-length.md): HTTP request content length should be limited
- [sonarjs/comma-or-logical-or-case](https://lintradar.dev/rules/sonarjs/comma-or-logical-or-case.md): Comma and logical OR operators should not be used in switch cases
- [sonarjs/content-security-policy](https://lintradar.dev/rules/sonarjs/content-security-policy.md): Content security policy fetch directives should not be disabled
- [sonarjs/code-eval](https://lintradar.dev/rules/sonarjs/code-eval.md): Dynamic code execution should not use user-controlled data
- [sonarjs/cookie-no-httponly](https://lintradar.dev/rules/sonarjs/cookie-no-httponly.md): Cookies should have the "HttpOnly" flag

---

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