Skip to content

eslint/prefer-template Style

🚧 An auto-fix is still under development.

What it does

Require template literals instead of string concatenation.

Why is this bad?

In ES2015 (ES6), we can use template literals instead of string concatenation.

Examples

Examples of incorrect code for this rule:

js
const str = "Hello, " + name + "!";
const str1 = "Time: " + (12 * 60 * 60 * 1000);

Examples of correct code for this rule:

js
const str = "Hello World!";
const str2 = `Time: ${12 * 60 * 60 * 1000}`;
const str4 = "Hello, " + "World!";

How to use

To enable this rule in the CLI or using the config file, you can use:

bash
oxlint --deny prefer-template
json
{
  "rules": {
    "prefer-template": "error"
  }
}

References

Released under the MIT License.