comma-style
强制使用一致的逗号样式
一些该规则报告的问题可以通过 --fix 命令行选项 自动修复
逗号样式规则强制使用逗号分隔列表的样式。JavaScript 中主要使用两种逗号样式:
- 标准样式,其中逗号放在当前行的末尾
- 逗号优先样式,其中逗号放在下一行的开头
使用 Comma First 样式的理由之一是它可以帮助跟踪缺少和尾随的逗号。这些都是有问题的,因为变量声明中缺少逗号会导致全局变量泄漏,而尾随逗号会导致旧版本 IE 中的错误。
规则详情
y//w7ysucDvlSOdV1SUXXkYxmoU7FN8r5ki5eq9TiH8NlgKqdqjN4Se2lPHG1s0YA3pUFYbW9arVDNEs6Qnoq65gLCnHIR139Uv3YGLCpdS/FsczqzC5chy1UVIfPWys
iCiaVx5FuwUKvnYLUDsS3UB4Di5W5L2sfhOHQmecINR+A53/eeLrM5jDGT4Fgd5IuH73TlGIwe5reKm11LaKXA==
- vG4tPDozJdr4uX6JSCohbGq268FPTSV7ONTEgM1Pw7eiOfBoMghZ2CjSKFfMCCXyFig6hdUALR4v3Bb5YZOR7emDc6/Q6/0y7aYkApfa32/LzPkUVKlDTZKrwiYUZX6ZfW28E5GFma5BCwOUic3Kzzy4b4b9e3RK2Lcph9pEV58=
选项
VtL0QjEmIoPGGZlPIOT+lCPHCGcc3pzkW2DWeMVOvNfi9lWqrXd1TrfH2U3osAuE
- 6iIKmsLfyjMcP2a31F1yUGDRM81Pt6Sepua2mskJqVrV4kQNPWJgpSK0yERUEzu0tOfG10N+laqaBZdsufYKWBmedTA0EePcs+Q0Dt8qT5REdV3c4iPBF1kN4hnb/udzFpnURKw+cfmC+cUxY4UUfgKAyPQGGU8EOBA1xu3D7IF9jkdXmtWUQW+PmbQfNR/ruLrm/ubEZNuhsODESyEPT1FQMycfSOPYB7gyKCfCkIpBGZjfEStw4EmdiKCObaCLh/S+gA7MLzAdGrL4xCGa/P7CC9YoNzRRJy9OKWtJSAZHx8ANrDHmILR5aC6au4m+IGKnsQNb+VZVrrlJWk7x/Q==
GIlrXHm4As2effWAtnayB4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paKu8XogtKb01QHdo0ULhCaKZ++kR1Aan/vhFhEUCcbjy8qApS89oVz3+LxHRCcsICFCVcgpfEg6YLubKTcBMTY1a3gfU0nM5D2RuJ41494aF+E+FHhXf6m01UGNubgGNaDsSxl6gDgaumrBwrR9y/J+rURsotGG4dCkLc3iOIt/8vw1o8d6y0wPbr92ZBGftO4gN7UiMm4Neb4uNhvZm/vOmRpLdJNK4cN2+A4k4i2jsYF+qzp73QUDEuwwMy3ALI50bLzN91jCDpzzCbIFlWBUc/3Z9Lu17WzumE6l8zYsa7jolqLIuBjdU9f67xwEC15eROe8zFIKQtIsGUe+J502aA/hE4SJWtogO2+D4U0UcTeFkPReLaHE3kc74ydfBwFr3fau4v872qd8dPugfKzahA9vOwxzb+BnoP+f/1LeTmEIOnZgfcILfZ9W8IcoSCl0MwV4LcTmzji2iRamOQ/I4evB6j5emYKMd1ZIcqAONVfiJpGkdn8bm8ONEqNX8EUkH5U9MQe3TsrwaFrbwkK6GmttLfZdYo5h3
+YvjBuORhR97vrDth3YBRnjGIcGesfFh0dDAJW6x+m1wos6mj8pIEgFzJ2VbDZZ5ejn6nlpVTgwBCxG7WT/DVJfRTRQHymoUkLJxmi8zeipAvZgZhjZ2wKLtOsO5VCgLeUO1vqEN4aYtSTvCWa1iZaFL51JdHFUOR389mp7o63Hr5rpYOhsH+QpoH7yj9NLFivjhMMr3z1Rp+bc/TVQ3k/kMD/mx9L7FDDoBgNIwR7R9Ur1e40QI9/cqxbcWjGimvnoz62ONeI8RKZmvJKbEEA==
last
gG4UUCWpCvzqVaU47Ruen2J2ozeVmms3s3nlA4B4xh8BtrhyenbGSjCRT6Fu9Mm3ulhs08ujnbwfyUwZVIgYEFGuxE4tRcedGVIif8sNya0=
/*eslint comma-style: ["error", "last"]*/
var foo = 1
,
bar = 2;
var foo = 1
, bar = 2;
var foo = ["apples"
, "oranges"];
function bar() {
return {
"a": 1
,"b:": 2
};
}
gG4UUCWpCvzqVaU47Ruen2J2ozeVmms3s3nlA4B4xh8BtrhyenbGSjCRT6Fu9Mm3jx4pphK+/dPhR3CNMKuARNYGRfloo1qz4wsWxPkfkS4=
/*eslint comma-style: ["error", "last"]*/
var foo = 1, bar = 2;
var foo = 1,
bar = 2;
var foo = ["apples",
"oranges"];
function bar() {
return {
"a": 1,
"b:": 2
};
}
first
TlLpo7HIJjIy2v3f96HaCa4hLqyI8uVHdVXMnYyYMIjWLdLQsKRrkK7iBeuNWnEMroof+b7ttI40biFOm6ZL4gmFlfiBkvHAYbBkXl3JsXE=
/*eslint comma-style: ["error", "first"]*/
var foo = 1,
bar = 2;
var foo = ["apples",
"oranges"];
function bar() {
return {
"a": 1,
"b:": 2
};
}
TlLpo7HIJjIy2v3f96HaCa4hLqyI8uVHdVXMnYyYMIjaStDZJpp8/hmkqNKwGU+yATdE3RvQaatrCbKpt/hdlxNIkUVKuUUZopXJhjV8rao=
/*eslint comma-style: ["error", "first"]*/
var foo = 1, bar = 2;
var foo = 1
,bar = 2;
var foo = ["apples"
,"oranges"];
function bar() {
return {
"a": 1
,"b:": 2
};
}
exceptions
oOuLv8cdor0NMhmRaoJZcHGJLv/Yxohrk0pW7XhikhV/g7loyk+WYQN4j31HPTUg/olmGQBE8/9Y9aRHs6kcA8ErX+eVCJenp9bMkzQPAk4=
usUFST+XNaC0G4FBYCpW1v2kXpZ5nU9YAS3fj3D0x4HAkpqjTB6lWEo9tlixXnPBr3NPnnfLjnXnfzHslu4jTq5t+xMxkoFlAu9zFOfGmdHK3wi8mhAe7XHZHmMSxtlvRJVTV61H0o6BufBb/hv+oA==
/*eslint comma-style: ["error", "first", { "exceptions": { "ArrayExpression": true, "ObjectExpression": true } }]*/
var o = {},
a = [];
usUFST+XNaC0G4FBYCpW1v2kXpZ5nU9YAS3fj3D0x4HAkpqjTB6lWEo9tlixXnPBr3NPnnfLjnXnfzHslu4jTq5t+xMxkoFlAu9zFOfGmdF+Y866EmtxYbSaAshytYDrzFKMk5Bo+SJhrQH0Y1jG8w==
/*eslint comma-style: ["error", "first", { "exceptions": { "ArrayExpression": true, "ObjectExpression": true } }]*/
var o = {fst:1,
snd: [1,
2]}
, a = [];
何时不使用
OZms8kFcz9eIGgvI3YdJZFpmoRmUgrSfK5rMhyvqscEWrLgU3QD1sdPRDDyeeN40QHIaDnU1WiJDvd1O4DZ/U9hSyo8+KjOHWQjFOgeTsajCfm6h6bGenXdSFrQEFDAvy5o2+ra81ctlj9jCVEC4dg==