简体   繁体   English

ESLint 双引号中的双引号

[英]ESLint Double Quotes in double quotes

I am using ESLint to format my Javascript code.我正在使用 ESLint 格式化我的 Javascript 代码。 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.我收到一个 ESLint 警告,告诉我“字符串应该使用双引号”,所以我继续将周围的单引号更改为双引号,并转义了内部双引号。 This lead to an ESLint error, which suggested I use the single quotes exactly as you see above.这会导致 ESLint 错误,这表明我完全按照您在上面看到的那样使用单引号。

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.信息:我被 ES5 困住了。

Many thanks in advance!提前谢谢了!

You can:你可以:

  • Escape double quotes in double-quoted strings ( "<div id=\"" + sId + "\" "; )转义双引号字符串中的双引号 ( "<div id=\"" + sId + "\" "; )
  • Turn off the linting rule which requires double-quoted strings关闭需要双引号字符串的 linting 规则
  • Use a template literal instead (but that requires ES6 so you'd need to transpile it to ES5 afterwards)改用模板文字(但这需要 ES6,因此您需要在之后将其转换为 ES5)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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