comma-spacing

在逗号前后强制保持一致的间距

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

逗号周围的间距提高了项目列表的可读性。尽管大多数语言的样式指南都规定在逗号之后而不是之前添加空格,但这取决于项目的偏好。

var foo = 1, bar = 2;
var foo = 1 ,bar = 2;

规则详情

该规则在变量声明、数组字面量、对象字面量、函数参数和序列中强制逗号前后的间距保持一致。

本规则不适用于下列任何一种情况:

    1VFV34BrARuZsnXBg8HiQQ/AzlkvcMtjfz7ZXAw+ur5MG5uu71Lpfh47bjiRomD5PXIwOFFVMWLRRcxBIRYtnf6BGKTlPa283Vn7PveQwyivALBkjqdZCA3ineb1UJ9ss8bt1VwXszvw+c+ltKj1VnrpgN5bhb1kYA9yGYCln1AZJkbzECs8cyt8QYzeGDH8gyiZAJOc1qhn5L11rlQ9QxXlucnsZmfgOlplWuHr/NeTqrYqPybM6LBV3xA4B0035dKTkcEgjU75BkrzBgmrhmb61RcDnUUsSOpnadRZVGu08CKeK0lbpAuLq2fCTb+OJhl9sh5KOK5XBF5vC3yGjGCsYaAL4jvFKfzf/eXncGhO09kLw+5z/M7HoLkdoOfs0uhUYZmcC7G+1TkZWhN2okTuaJzdawa9b4Olko2hQnwh45MplAqJFSymQ8kLTqaaqPr1UOFy/q0VIEIdvDGqXxZajBOhmKCmG3bB5Ag3vaeVIfuRk9i8dcEhiir1+dFlBEaLOj0YsYxu9PVCP5UfZ8/9UtUwftANooeuTlvA0fUiMDzLRo2Lxv5NNUiRupDlceC43kO0hnCSJbzg4EdiPsnqUm4jb8ACbGolRFR386k/Bx6Qb3x5D4//i8SpN75iW8obwpXyVUG0SMKqOmWIFB5ubvIX4MjL+IiB9zikJFQtDs/r6zdyVjMSQ1IRxBCCb/vAzKPfRmZ4ooUhhoPt3D6hbvu2c7WnJ5dfydx1+52Nkn6XqEXOV4f1cZoNURJX98aNyPRGAaeVmJZ3os44ykTyzSksm+gDu3nON5qokgZZv6qfidMksuJ+ANxByZPc7nSRha3yo7S2feXl1zRRf4DXyB/9UimDuGBorLIwtiC/E4ePZ8BAiYUBb5FlG++XeUmhd7TGPLqwdR+sb6yurA==

选项

8tpaQvHwOW6egTxtmGETxTflp+BGPa3VKRHMK6uHuifLZs6g/rHfZStGUFNk/xHg

    dtpr+bxPkTya3P9f1hXZlu3iyFr5ptRb91LddTV0irDKPlxkatDC9/M4UabSX5LsCyEYXaHkWogblUwHTStUjtbmqGgsxssrYXQwFh5NCw5JRC1r1HvymDJzpPgTh3E5VXApOiKisLNqndu+pIq+pWZLiZ/KHgGNS8SQ0Ywr0rrxh4X06OKf2qjZ/68IlyX2MixxQNERfGUcMazzC+iJsB6Bg+mTK29enCigZuzHOjGat4uwAQC/4w32mq8aZorKlwAyywXuYvxC0sp1bfMFO+fXnKfxKoZ8PoO+AkhbnZtYDx0gSlCZwLaBvjrETkqXK2vPwYpgPPBhpKjik3l83o+9zZD33bpUtIUTBOgV4SNgTepxYlxV23Pn0zQKLVf3DvI6q/Xng/LrOyWg7jZAGkwcsrdUB0hn5+FGGQzxViU=

after

v7zYOf63la3G5M6x9J6kaZeaN8+5G9emXPc7zvRnmk+oWNA9Sd1agzl5AafnvaHEHiGi8utOyYLEtFi7bp9wVpvdd32PQ5Ju4RTF9Ufr00Xu//60zYX3+lZudWDEtYrW8uqwkpwS91aONHuBlwrPMQ==

/*eslint comma-spacing: ["error", { "before": false, "after": true }]*/

var foo = 1 ,bar = 2;
var arr = [1 , 2];
var obj = {"foo": "bar" ,"baz": "qur"};
foo(a ,b);
new Foo(a ,b);
function foo(a ,b){}
a ,b

v7zYOf63la3G5M6x9J6kaZeaN8+5G9emXPc7zvRnmk+oWNA9Sd1agzl5AafnvaHEHiGi8utOyYLEtFi7bp9wVpvdd32PQ5Ju4RTF9Ufr00VPIpm6gNwhYRXEOC5+iFbUeNXVIK3WqB/R8aQ1hzLmMA==

/*eslint comma-spacing: ["error", { "before": false, "after": true }]*/

var foo = 1, bar = 2
    , baz = 3;
var arr = [1, 2];
var arr = [1,, 3]
var obj = {"foo": "bar", "baz": "qur"};
foo(a, b);
new Foo(a, b);
function foo(a, b){}
a, b

v7zYOf63la3G5M6x9J6kaZeaN8+5G9emXPc7zvRnmk+oWNA9Sd1agzl5AafnvaHEHiGi8utOyYLEtFi7bp9wVpvdd32PQ5Ju4RTF9Ufr00V7JFV6hcgTRFSAHv1ZYp6QM/6gzi+zqa07oaiR2Mwwhbv/CYuUioc1CKddcTphqCQ=

/*eslint comma-spacing: ["error", { "before": false, "after": true }]*/

// this rule does not enforce spacing between two commas
var arr = [
    ,,
    , ,
];

// this rule does not enforce spacing after `[` and before `]`
var arr = [,];
var arr = [ , ];
var arr = [a, b,];
[,] = arr;
[ , ] = arr;
[a, b,] = arr;

// this rule does not enforce spacing before `}`
var obj = {x, y,};
var {z, q,} = obj;
import {foo, bar,} from "mod";

// this rule does not enforce spacing before `)`
foo(a, b,)

before

yOPmeunUbyT4mmCnPBjZ7ZXd5gpn7jyRDWRnBBI7qLvHubes59KzgFrfdf3UdkfBooE6EOFQstHCiZHSlRV3mEkrg6QIe+6MBY4mZb6ejYYI4cySTljqS5z0rDN7XVVb

/*eslint comma-spacing: ["error", { "before": true, "after": false }]*/

var foo = 1, bar = 2;
var arr = [1 , 2];
var obj = {"foo": "bar", "baz": "qur"};
new Foo(a,b);
function foo(a,b){}
a, b

yOPmeunUbyT4mmCnPBjZ7ZXd5gpn7jyRDWRnBBI7qLvHubes59KzgFrfdf3UdkfBooE6EOFQstHCiZHSlRV3mE/d6nDs5xBAaNNC+TmNUdOY16vlSBVaCCGHIW1ONdLS

/*eslint comma-spacing: ["error", { "before": true, "after": false }]*/

var foo = 1 ,bar = 2 ,
    baz = true;
var arr = [1 ,2];
var arr = [1 ,,3]
var obj = {"foo": "bar" ,"baz": "qur"};
foo(a ,b);
new Foo(a ,b);
function foo(a ,b){}
a ,b

何时不使用

U+sCL60Qw70yWdPIegOMnxV+2xiG7Z1ojp7VVlQwJKKkPUFdOAFupT/FVIpEieIz2pw/BOk4XVDD+gapr5CDgybg/9fRjr+F5nqSUO2w32WqwNEl8tPYQeG40Ak7zyhJ