简体   繁体   中英

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!

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM