> For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt.

# prefer-template

[Added in v0.5.0](https://github.com/web-infra-dev/rslint/releases/tag/v0.5.0)
## Configuration


```ts title=rslint.config.ts
import { defineConfig, js } from '@rslint/core';

export default defineConfig([
  js.configs.recommended,
  {
    rules: {
      'prefer-template': 'error',
    },
  },
]);
```

## Rule Details

This rule is aimed to flag usage of `+` operators with strings. It encourages
the use of template literals instead of string concatenation.

Examples of **incorrect** code for this rule:

```javascript
var str = 'Hello, ' + name + '!';
var str = 'Time: ' + 12 * 60 * 60 * 1000;
```

Examples of **correct** code for this rule:

```javascript
var str = 'Hello World!';
var str = `Hello, ${name}!`;
var str = `Time: ${12 * 60 * 60 * 1000}`;
```

This rule does not report two string literals concatenated together (for
example, `"Hello, " + "World!"`), which is reported by the
[`no-useless-concat`](https://eslint.org/docs/latest/rules/no-useless-concat)
rule instead.

The rule provides an autofix that rewrites the concatenation as a single
template literal, preserving comments around the `+` operators. Autofix is
skipped when any operand contains an octal or non-octal-decimal escape
sequence, because those cannot be represented in a template literal.

## Original Documentation

- [ESLint: prefer-template](https://eslint.org/docs/latest/rules/prefer-template)
- [Source code](https://github.com/eslint/eslint/blob/v10.2.1/lib/rules/prefer-template.js)
