# no-same-line-conditional

Rule `sonarjs/no-same-line-conditional`. Conditionals should start on new lines

- 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: #1313 by reach, #614 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/no-same-line-conditional` | yes | suggestion | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-3972/) |

## Code examples

### Incorrect: the rule reports this

```js
if (condition1) {
  // ...
} if (condition2) {  // Noncompliant
  //...
}
```

### Correct: the rule accepts this

```js
if (condition1) {
  // ...
} else if (condition2) {
  //...
}
```

```js
if (condition1) {
  // ...
}

if (condition2) {
  //...
}
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/no-same-line-conditional": "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/no-same-argument-assert](https://lintradar.dev/rules/sonarjs/no-same-argument-assert.md): Assertions should not be given twice the same argument
- [sonarjs/no-selector-parameter](https://lintradar.dev/rules/sonarjs/no-selector-parameter.md): Methods should not contain selector parameters
- [sonarjs/no-regex-spaces](https://lintradar.dev/rules/sonarjs/no-regex-spaces.md): Regular expressions should not contain multiple spaces
- [sonarjs/no-session-cookies-on-static-assets](https://lintradar.dev/rules/sonarjs/no-session-cookies-on-static-assets.md): Static Assets should not serve session cookies
- [sonarjs/no-referrer-policy](https://lintradar.dev/rules/sonarjs/no-referrer-policy.md): HTTP Referrer-Policy should not be set to an unsafe value
- [sonarjs/no-skipped-tests](https://lintradar.dev/rules/sonarjs/no-skipped-tests.md): Tests should not be skipped without providing a reason

---

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