# prefer-specific-assertions

Rule `sonarjs/prefer-specific-assertions`. The most specific assertion should be used

- Source: sonarjs
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1350 by reach, #651 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/prefer-specific-assertions` | yes | suggestion | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-5906/) |

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/prefer-specific-assertions": "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/prefer-single-boolean-return](https://lintradar.dev/rules/sonarjs/prefer-single-boolean-return.md): Return of boolean expressions should not be wrapped into an "if-then-else" statement
- [sonarjs/prefer-type-guard](https://lintradar.dev/rules/sonarjs/prefer-type-guard.md): Type predicates should be used
- [sonarjs/prefer-regexp-exec](https://lintradar.dev/rules/sonarjs/prefer-regexp-exec.md): "RegExp.exec()" should be preferred over "String.match()"
- [sonarjs/production-debug](https://lintradar.dev/rules/sonarjs/production-debug.md): Debugging features should not be enabled in production
- [sonarjs/prefer-read-only-props](https://lintradar.dev/rules/sonarjs/prefer-read-only-props.md): React props should be read-only
- [sonarjs/pseudo-random](https://lintradar.dev/rules/sonarjs/pseudo-random.md): Pseudorandom number generators (PRNGs) should not be used in security contexts

---

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