# hooks-before-test-cases

Rule `sonarjs/hooks-before-test-cases`. Lifecycle hooks should not be interleaved with test cases or nested suites

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

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/hooks-before-test-cases` | yes | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-8782/) |

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/hooks-before-test-cases": "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/hashing](https://lintradar.dev/rules/sonarjs/hashing.md): Weak hashing algorithms should not be used
- [sonarjs/in-operator-type-error](https://lintradar.dev/rules/sonarjs/in-operator-type-error.md): "in" should not be used with primitive types
- [sonarjs/hardcoded-secret-signatures](https://lintradar.dev/rules/sonarjs/hardcoded-secret-signatures.md): Credentials should not be hard-coded
- [sonarjs/inconsistent-function-call](https://lintradar.dev/rules/sonarjs/inconsistent-function-call.md): Functions should be called consistently with or without "new"
- [sonarjs/generator-without-yield](https://lintradar.dev/rules/sonarjs/generator-without-yield.md): Generators should explicitly "yield" a value
- [sonarjs/index-of-compare-to-positive-number](https://lintradar.dev/rules/sonarjs/index-of-compare-to-positive-number.md): "indexOf" checks should not be for positive numbers

---

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