Lint Rules

useTemplate (since v0.7.0)

This rule is recommended by Rome.

Template literals are preferred over string concatenation.

Examples

Invalid

console.log(foo + "baz");
style/useTemplate.js:1:13 lint/style/useTemplate  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Template literals are preferred over string concatenation.
  
  > 1 │ console.log(foo + "baz");
               ^^^^^^^^^^^
    2 │ 
  
   Suggested fix: Use a TemplateLiteral.
  
    1  - console.log(foo·+·"baz");
      1+ console.log(`${foo}baz`);
    2 2  
  
console.log(1 * 2 + "foo");
style/useTemplate.js:1:13 lint/style/useTemplate  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Template literals are preferred over string concatenation.
  
  > 1 │ console.log(1 * 2 + "foo");
               ^^^^^^^^^^^^^
    2 │ 
  
   Suggested fix: Use a TemplateLiteral.
  
    1  - console.log(1·*·2·+·"foo");
      1+ console.log(`${1·*·2}foo`);
    2 2  
  
console.log(1 + "foo" + 2 + "bar" + "baz" + 3);
style/useTemplate.js:1:13 lint/style/useTemplate  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Template literals are preferred over string concatenation.
  
  > 1 │ console.log(1 + "foo" + 2 + "bar" + "baz" + 3);
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    2 │ 
  
   Suggested fix: Use a TemplateLiteral.
  
    1  - console.log(1·+·"foo"·+·2·+·"bar"·+·"baz"·+·3);
      1+ console.log(`${1}foo${2}barbaz${3}`);
    2 2  
  
console.log((1 + "foo") * 2);
style/useTemplate.js:1:14 lint/style/useTemplate  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Template literals are preferred over string concatenation.
  
  > 1 │ console.log((1 + "foo") * 2);
                ^^^^^^^^^
    2 │ 
  
   Suggested fix: Use a TemplateLiteral.
  
    1  - console.log((1·+·"foo")·*·2);
      1+ console.log((`${1}foo`)·*·2);
    2 2  
  
console.log("foo" + 1);
style/useTemplate.js:1:13 lint/style/useTemplate  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Template literals are preferred over string concatenation.
  
  > 1 │ console.log("foo" + 1);
               ^^^^^^^^^
    2 │ 
  
   Suggested fix: Use a TemplateLiteral.
  
    1  - console.log("foo"·+·1);
      1+ console.log(`foo${1}`);
    2 2  
  

Valid

console.log("foo" + "bar");
console.log(foo() + "\n");