ESLint/Prettier rule to disallow template literals without placeholders

Viewed 310

Is there an ESLint or Prettier rule that would disallow template literals without a placeholder? I would like to replace backticks in template literals without placeholder with standard quotation marks '';

Allowed

const templateLiteral = `Some ${string}`;

Disallowed

const templateLiteral = `Some string`;

Turned into

const templateLiteral = 'Some string';
1 Answers

The quotes eslint rule helps you enforce single quotes. Add the following to your .eslintrc:

"rules": {
  "quotes": ["error", "single", { "avoidEscape": true }]
}

You can verify that backticks/template literals without any expressions/substitutions are disallowed in the rule test code.

Related