# no-collapsible-if

Rule `sonarjs/no-collapsible-if`. Mergeable "if" statements should be combined

- Source: sonarjs
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: no
- Reach: 0 weekly downloads of presets that enable it
- Trend: 0% last quarter
- Rank: #2144 by reach

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/no-collapsible-if` | no | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-1066/) |

## Code examples

### Incorrect: the rule reports this

```js
if (x != undefined) {
  if (y === 2) {
    // ...
  }
}
```

### Correct: the rule accepts this

```js
if (x != undefined && y === 2) {
  // ...
}
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/no-collapsible-if": "error",
    },
  },
];
```

## Related rules

- [sonarjs/no-built-in-override](https://lintradar.dev/rules/sonarjs/no-built-in-override.md): Built-in objects should not be overridden
- [sonarjs/no-commented-code](https://lintradar.dev/rules/sonarjs/no-commented-code.md): Sections of code should not be commented out
- [sonarjs/nested-control-flow](https://lintradar.dev/rules/sonarjs/nested-control-flow.md): Control flow statements "if", "for", "while", "switch" and "try" should not be nested too deeply
- [sonarjs/no-duplicate-string](https://lintradar.dev/rules/sonarjs/no-duplicate-string.md): String literals should not be duplicated
- [sonarjs/max-union-size](https://lintradar.dev/rules/sonarjs/max-union-size.md): Union types should not have too many elements
- [sonarjs/no-empty-test-file](https://lintradar.dev/rules/sonarjs/no-empty-test-file.md): Test files should contain at least one test case

---

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