user1728
user1728

Reputation: 103

ESLint Double Quotes in double quotes

I am using ESLint to format my Javascript code. There I have the following piece of code:

'<div id="' + sId + '" '; ...

I get an ESLint warning telling me 'Strings should use double quotes', so I went ahead and changed the surrounding single quotes to double quotes and escaped the inner double quote. This lead to an ESLint error, which suggested I use the single quotes exactly as you see above.

Is there a way to solve this conflict so that I don't get the error or the warning? Info: I am stuck with ES5.

Many thanks in advance!

Upvotes: 0

Views: 934

Answers (1)

Quentin
Quentin

Reputation: 943696

You can:

  • Escape double quotes in double-quoted strings ("<div id=\"" + sId + "\" ";)
  • Turn off the linting rule which requires double-quoted strings
  • Use a template literal instead (but that requires ES6 so you'd need to transpile it to ES5 afterwards)

Upvotes: 1

Related Questions