quotes

强制一致地使用反引号、双引号或单引号

一些该规则报告的问题可以通过 --fix 命令行选项 自动修复

JavaScript 允许您以以下三种方式之一定义字符串:双引号、单引号和反引号(从 ECMAScript 6 开始)。例如:

/*eslint-env es6*/

var double = "double";
var single = 'single';
var backtick = `backtick`;    // ES6 only

这些行中的每一行都创建一个字符串,在某些情况下,可以互换使用。选择如何在代码库中定义字符串是模板字面(允许解释嵌入的表达式)之外的一种风格。

许多代码库要求以一致的方式定义字符串。

规则详情

LNI41f429lrCektBCmtFt5eieG13H+r055pu8d1EvVelrytoH2fAJ40gLAZzwpcx3ASK8ejiXDAnlcR3UKmurj/xOYtRSgn7axumrwECd44=

选项

/npZAcDo0Oet0elPDURsSaSbikTeV2nuU56ne2pc7ydvD63s0xYicHgWw0iB+DGRpi6APUH5qpwUJkQwunCQBkZZmqjdeiu9Om1PWBYQwjM=

b1KgIlAwFlhpGCu0zfrSElu30N8/t827vOY+41JdOX0=

    5hWGJg6KzcDeCg13PanyD5Pmldf+cNC1A3zvGNkQwS+Hv64Rbg9QY7zXPTlJuxxLJouB7EdZ3NGG3Fr5W9+S56atfPWHjxVtTJgNb2Du8bvSZcRwta9hsT10IPBiU4rb2sgSpYwixpHwLz4Mb//jMaBnRnZwsUHgNpllXiREF+zcTzqMg2QMGJZUOaz71BwUSQxZfjWVta4VfrxGALk5V5KHADjTGJ6RFlhRExOd0Ha1zDxz3xOFYWFmcJCpPXl6zEhuAvbQ5KSVpD8eNogjPw==

zSZbdgeZw55DayEAZ+I5tA==

    yJB+Tb4DfoNWo6A+bb4FnQuUKNcbiPYvyhxuifCTh3p2SjAlU27YxYpflnJ8B9EA1svB/FBNafAAjroPHNDGPgUyEMznHXHF5Pz0FwYvY+xyi8gE3uQFcFT/Am2Gv60wlMR7ATzj6MmDmQJqJyyXJLOzbhl2SthwdKW31Y3aAQ5QXjRxconvAtzTLn8yyh7mNB2XjwxDUKR/knlVekdicpUafwgF7CIk+Zavj8MIEoPWdxYkZqavDvF5fCGhz6cyRVlMeQGxgGV3c1PysBrBlI5qFY/XnWN3vfwaBeGKzkQ=

JLlhSYlTFit/B7Ajv2RIicyMUxLP1N01jDU9dYJpvSCMdoLa5p+j/YVtyj3E7LzyRvC3XZjXPVO6ij9/YNZJOCPKthbzOIJYzrRZXpPKCGYivesloBgIcAATvY+tC49/3mLAkgmc+YJWlYWWDF7deYcdYKgVWB+wObCu+DS2oyOLbJyfupnm7TJ8ngS4fNoP

double

nlpQkElgf/TvKUOwoIVk1NL8iUJHoqQrUxd4PSiZwBshgfAmGWFKtdxQdCGLzRKnGgnLu7sX1QnQzytfcENjcnhxWMzyBeeC+9rhjmqNIHE=

/*eslint quotes: ["error", "double"]*/

var single = 'single';
var unescaped = 'a string containing "double" quotes';
var backtick = `back\ntick`; // you can use \n in single or double quoted strings

nlpQkElgf/TvKUOwoIVk1NL8iUJHoqQrUxd4PSiZwBshgfAmGWFKtdxQdCGLzRKnwQzYFaP3l2yRf03e6APsb+k2j2CoOYUJ9rYBT0FQF/c=

/*eslint quotes: ["error", "double"]*/
/*eslint-env es6*/

var double = "double";
var backtick = `back
tick`;  // backticks are allowed due to newline
var backtick = tag`backtick`; // backticks are allowed due to tag

single

gzlG8jANWr4Hhb4/2Xwr9yGd97y2iKj7bNKVhGV3jrkKppgyxzKTGs8U5pyPnSAmuYgMmyTpvNWuphAeUKP1v1RR8Zixh+vmXMc4K69NXlA=

/*eslint quotes: ["error", "single"]*/

var double = "double";
var unescaped = "a string containing 'single' quotes";

gzlG8jANWr4Hhb4/2Xwr9yGd97y2iKj7bNKVhGV3jrn14LZYhBrUpP+X9H2Mns/lD4m2/9FYEw+dZHVnXRHnBm7z7AHp1oTr0+zUohUFlGg=

/*eslint quotes: ["error", "single"]*/
/*eslint-env es6*/

var single = 'single';
var backtick = `back${x}tick`; // backticks are allowed due to substitution

backticks

gzlG8jANWr4Hhb4/2Xwr9zGiuFmDWiHQKgzrKzo0VcN5IYGJap+E2Fvyk2LsuFtfh7NAtPjupiDR+HqkQh4v6oar3YwP5dmv/lVSHeqh8ZM=

/*eslint quotes: ["error", "backtick"]*/

var single = 'single';
var double = "double";
var unescaped = 'a string containing `backticks`';

gzlG8jANWr4Hhb4/2Xwr9zGiuFmDWiHQKgzrKzo0VcN5IYGJap+E2Fvyk2LsuFtfxHflZjTbKgLoE6sSa6Qmzj1oDrATZWK8q0cYpTvJHYc=

/*eslint quotes: ["error", "backtick"]*/
/*eslint-env es6*/

var backtick = `backtick`;

avoidEscape

gzlG8jANWr4Hhb4/2Xwr97ngLvzAQtsH4EN/zz1CYpN2xrhACIPOZQiv+HqLlcaE73T/6UT2Oyn5QyoAJfII/ybQRcayDJ15GXMeAyPG3+pvkU9NJQqYngHerNoFGiZdAB+azNQA8x3jly7t7eaJlw==

/*eslint quotes: ["error", "double", { "avoidEscape": true }]*/

var single = 'a string containing "double" quotes';

gzlG8jANWr4Hhb4/2Xwr9xfUE9T++xzsGCxgytBP8jlDZswMS/Y+KRtjZ3Y+Wn0skHsuJlq8/9vIrdHUGUss71efUqHPqN6/I1PfN6w2qPxlm1I+OMld01TIlfXPd/N+7aXfB/Y5+YSeT/ge8h8+8w==

/*eslint quotes: ["error", "single", { "avoidEscape": true }]*/

var double = "a string containing 'single' quotes";

gzlG8jANWr4Hhb4/2Xwr9zGiuFmDWiHQKgzrKzo0VcNAouEOYw4McIpYvewZgh5z/6aKuhko209wTHprl4fym/ot9iQEHpLS+uwkebHyHP9zyhlWZ74smyLgp9qzxH3sUADnw08ycNGfWYwhmQtcMw==

/*eslint quotes: ["error", "backtick", { "avoidEscape": true }]*/

var double = "a string containing `backtick` quotes"

allowTemplateLiterals

gzlG8jANWr4Hhb4/2Xwr97ngLvzAQtsH4EN/zz1CYpPHTonynofg1dhclojzFInAuBewlBOCGAM3Feg4Ubjt17DiTZZZ/qq5C0EpQ0yz8jParP4Z6d3ZtEysHpYB1GgfdEIvc98tKHxVOD6MRGVlIA==

/*eslint quotes: ["error", "double", { "allowTemplateLiterals": true }]*/

var double = "double";
var double = `double`;

gzlG8jANWr4Hhb4/2Xwr9xfUE9T++xzsGCxgytBP8jllKx3pPuDsKpHgO6UWwOFGPEsbFKtAES33zd30QAMF1+kZrSvXhrQ0bcFvSFqX0mcA4SEqGLJBqoMYjcsx/pQLz1huG//p7tl/D3LwJtiA+Q==

/*eslint quotes: ["error", "single", { "allowTemplateLiterals": true }]*/

var single = 'single';
var single = `single`;

5b7CiFYv0vdSdUf/DR+Ra6Wz8agr++a9/oC9VB8JKBw6SGbpvxcZ34vpNssWjsIjFQ0767zuijFeHn1qRlT5mxfr1vRRgTJTJ3plic0EQi827Q5lE3maQ9nBG+GOjggSopzI67aE2yX01Pc8Ph5W9FPZUFYv6OeOI/x86ayxH+l0fIHG+5kktl8GQUqyD2I01q1OvpRd0cq9J94bZW67Nohu/AELI4+9rx9aj2bEfr1t1M5/rthXrwN+JzgovcY5EqhZRUfgEeJnk5jTYQePFfuVhbPy4+fU+/TT2zn6cNDD2J2aGBMyQmBVVgOj8BisQic2K3s2ACyuU+HwsrDN1qvKDhbg9CnIjRCkKrt/Ss0=

何时不使用

Tgo1y4Ixe+U9d+91pye6qHZ5ZzbbhLXwurvZuLN+muJV+ftCmM6HC5cnc+JegHBgwdFgoEeRdOHnOMVSg9t1rxF9uhUGrKPRkVu/JP9eGWT4nHJNcmnWDF8COrdbQZ0x