Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-3786

Template literal placeholder syntax should not be used in regular strings

    XMLWordPrintable

    Details

    • Type: Bug Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
      None
    • Message:
      Replace the quotes (["|']) with back-ticks (`).
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way recommended
    • Covered Languages:
      JavaScript, TypeScript
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      1min
    • Analysis Scope:
      Main Sources, Test Sources
    • ESLint:
      no-template-curly-in-string
    • TSLint:
      no-invalid-template-strings

      Description

      Template strings allow developers to embed variables or expressions in strings using template literals, instead of string concatenation. This is done by using expressions like ${variable} }} in a string between two back-ticks ({{`). However, when used in a regular string literal (between double or single quotes) the template will not be evaluated and will be used as a literal, which is probably not what was intended.

      Noncompliant Code Example

      console.log("Today is ${date}"); // Noncompliant
      

      Compliant Solution

      console.log(`Today is ${date}`);
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            jeanchristophe.collet Jean-Christophe Collet (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: