# prefer-template

> Require template literals instead of string concatenation

In `"Hello, " + user.name + "!"`, quotes and plus signs cut the text into pieces, and a missing space at the edge of a piece is hard to see. A template literal keeps the text in one piece with the values in place.

A chain of `+` is reported if it mixes string literals with anything else. Joining only string literals is allowed, so you can still split a long string over two lines.

`--fix` rewrites the concatenation as a template literal.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"prefer-template" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 2} */}
```js
const greeting = "Hello, " + user.name + "!";
const url = base + "/users/" + id;
```

Not reported:

{/* good */}
```js
const greeting = `Hello, ${user.name}!`;
const url = `${base}/users/${id}`;

const total = price + tax;
const notice = "This sentence is long, " +
  "so it is written as two strings.";
```
