# no-lonely-if

Rule `eslint/no-lonely-if`. Disallow `if` statements as the only statement in `else` blocks

- Source: eslint
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 12.6M weekly downloads of presets that enable it
- Trend: +13.3% last quarter
- Rank: #742 by reach, #1429 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `no-lonely-if` | no | safe | package `eslint` | [docs](https://eslint.org/docs/latest/rules/no-lonely-if) |
| Oxlint | `no-lonely-if` | no | no | plugin `eslint`, category pedantic | [docs](https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-lonely-if.html) |
| Biome | `style/useCollapsedElseIf` | no | safe | group style, since 1.1.0 | [docs](https://biomejs.dev/linter/rules/use-collapsed-else-if/) |

## Code examples

### Incorrect: the rule reports this

```js
if (condition) {
    // ...
} else {
    if (anotherCondition) {
        // ...
    }
}

if (condition) {
    // ...
} else {
    if (anotherCondition) {
        // ...
    } else {
        // ...
    }
}
```

### Correct: the rule accepts this

```js
if (condition) {
    // ...
} else if (anotherCondition) {
    // ...
}

if (condition) {
    // ...
} else if (anotherCondition) {
    // ...
} else {
    // ...
}

if (condition) {
    // ...
} else {
    if (anotherCondition) {
        // ...
    }
    doSomething();
}
```

Examples from the ESLint documentation.

## Enable it

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

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

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "no-lonely-if": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "style": {
        "useCollapsedElseIf": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Airbnb base](https://lintradar.dev/presets/airbnb-base.md) | ESLint | `eslint-config-airbnb-base` | 241 | 6.5M | +2.1% |
| [Airbnb](https://lintradar.dev/presets/airbnb.md) | ESLint | `eslint-config-airbnb` | 346 | 3.4M | +2.3% |
| [Ultracite for Biome](https://lintradar.dev/presets/ultracite-biome.md) | Biome | `ultracite` | 616 | 2.1M | +151.7% |
| [Ultracite for Oxlint](https://lintradar.dev/presets/ultracite-oxlint.md) | Oxlint | `ultracite` | 475 | 2.1M | +151.7% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |
| [eslint-config-love](https://lintradar.dev/presets/love.md) | ESLint | `eslint-config-love` | 258 | 171.7K | +39.3% |

## Related rules

- [unicorn/no-lonely-if](https://lintradar.dev/rules/unicorn/no-lonely-if.md): Disallow `if` statements as the only statement in `if` blocks without `else`.
- [eslint/no-await-in-loop](https://lintradar.dev/rules/eslint/no-await-in-loop.md): Disallow `await` inside of loops
- [eslint/no-multi-assign](https://lintradar.dev/rules/eslint/no-multi-assign.md): Disallow use of chained assignment expressions
- [eslint/arrow-body-style](https://lintradar.dev/rules/eslint/arrow-body-style.md): Require braces around arrow function bodies
- [eslint/operator-assignment](https://lintradar.dev/rules/eslint/operator-assignment.md): Require or disallow assignment operator shorthand where possible
- [eslint/no-promise-executor-return](https://lintradar.dev/rules/eslint/no-promise-executor-return.md): Disallow returning values from Promise executor functions

---

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