# no-nested-template-literals

Rule `sonarjs/no-nested-template-literals`. Template literals should not be nested

- 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: #1161 by reach, #462 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/no-nested-template-literals` | yes | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-4624/) |
| Biome | `nursery/noNestedTemplateLiterals` | no | no | group nursery, since 2.6.0 | [docs](https://biomejs.dev/linter/rules/no-nested-template-literals/) |

## Code examples

### Incorrect: the rule reports this

```js
let color = "red";
let count = 3;
let message = `I have ${color ? `${count} ${color}` : count} apples`; // Noncompliant; nested template strings not easy to read
```

### Correct: the rule accepts this

```js
let color = "red";
let count = 3;
let apples = color ? `${count} ${color}` : count;
let message = `I have ${apples} apples`;
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/no-nested-template-literals": "error",
    },
  },
];
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "nursery": {
        "noNestedTemplateLiterals": "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/anchor-precedence](https://lintradar.dev/rules/sonarjs/anchor-precedence.md): Alternatives in regular expressions should be grouped when used with anchors
- [sonarjs/argument-type](https://lintradar.dev/rules/sonarjs/argument-type.md): Arguments to built-in functions should match documented types
- [sonarjs/arguments-order](https://lintradar.dev/rules/sonarjs/arguments-order.md): Parameters should be passed in the correct order
- [sonarjs/array-callback-without-return](https://lintradar.dev/rules/sonarjs/array-callback-without-return.md): Callbacks of array methods should have return statements
- [sonarjs/assertions-in-test-cases](https://lintradar.dev/rules/sonarjs/assertions-in-test-cases.md): Assertions should be placed inside test cases or hooks
- [sonarjs/assertions-in-tests](https://lintradar.dev/rules/sonarjs/assertions-in-tests.md): Tests should include assertions

---

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