space-in-parens
在括号内强制保持一致的间距
一些该规则报告的问题可以通过 --fix 命令行选项 自动修复
一些样式指南要求或不允许括号内有空格:
foo( 'bar' );
var x = ( 1 + 2 ) * 3;
foo('bar');
var x = (1 + 2) * 3;
规则详情
此规则将通过在 (
右侧和 )
左侧禁止或要求一个或多个空格来直接在括号内强制执行一致的间距。
只要您不使用 "empty"
异常明确禁止空括号,就允许使用 ()
。
选项
ecxF8F9INHja9BdL/PIkQIsg3JjLBzksbenobRFAzBQ=
- hvOXZlo2rjM4Xy1yQkmQbBYYf+vzXkgKadO/3pDeD6Lvs25Pi/8IgobBQx/v/REBw9Onll943tZCNoUV5/UogIaW68FVDEKM4Rb5uMRWomJqI7925fhVz6+HhUJA87f/7ihpLmjRjfr7GEoRV7IlIa56XRIE5iez4IoTLvK+g/55bMzMSPT1akesUXsn76ej
iqdJpRZY7/GDFqIRoF1Zlgs8LimtEh9LXHAt6xdQMKDdxd8q1c2v6YGLcOXpSS8TLryqooQvmt2/fY5MXpdy6r3eLayIkmG3O/8eB59G7apSiY4EqYnUV0+ecYPQjLss
"space-in-parens": ["error", "always"]
"never"
1usau4ITNzPbSW1XK9odV36T5eJrcl6PuhClRq6TuWdomgZ5GLx5YYPwyuPc107z+HpttBiqorx2oJVReN7lIve1XLew6jTp+NtKv25VdLg=
/*eslint space-in-parens: ["error", "never"]*/
foo( );
foo( 'bar');
foo('bar' );
foo( 'bar' );
foo( /* bar */ );
var foo = ( 1 + 2 ) * 3;
( function () { return 'bar'; }() );
1usau4ITNzPbSW1XK9odV36T5eJrcl6PuhClRq6TuWdomgZ5GLx5YYPwyuPc107zDmfdWL3eZvOfRJsSNXXHW+8rfTlM4FIS/uX6boW79WE=
/*eslint space-in-parens: ["error", "never"]*/
foo();
foo('bar');
foo(/* bar */);
var foo = (1 + 2) * 3;
(function () { return 'bar'; }());
"always"
dnC4C79+++7hmkZ7ssvw807GQ74olwDCAJLk9H37YfNokYbgqBl2m4ee3NKB1LSg0duDXBRQLp3Fw7tQKRQvMDRNAx3Jo21QEr/pKJLQpLw=
/*eslint space-in-parens: ["error", "always"]*/
foo( 'bar');
foo('bar' );
foo('bar');
foo(/* bar */);
var foo = (1 + 2) * 3;
(function () { return 'bar'; }());
dnC4C79+++7hmkZ7ssvw807GQ74olwDCAJLk9H37YfMglk8WQ/XEls4y4xwtaloz9U5ofl7PkKdM222tH1q2fvwtb6WuPFEwUqkY4YAqdo0=
/*eslint space-in-parens: ["error", "always"]*/
foo();
foo( );
foo( 'bar' );
foo( /* bar */ );
var foo = ( 1 + 2 ) * 3;
( function () { return 'bar'; }() );
异常
YK10nwRzYQjYTPX3hE0vkDzvbGtjnsl5bZOFS7EDHt4FbRVBozydLDVsJMOkyXPGDAI6EVRn2+cThH43Winl49Q8QN2iuakfv+0Uilz6BvKJUnukQtgDbnY2j3TtYxm/fY7XLDm6VxwhGmRYJZ4eHCE1qL0qA6R1WYuqAMVymjBBOJ1M5et1Igma5gS6FkqVt1Gff7XlLL4RLsqjwYIktVM4rXDC9Ftr4HTzYCtg4Bq8kQBr5PL6fpTm5k665QnDZd/4/TJgJ6aX8RWR1zEn6CQacukbT7g7WhMszzruRrgSP83hBWKJ38w04l3lIntG6jcrYcjlXEVGK3iKbqv1nUHZEGfmT3D0zOwl73xmHpubKTN0QzR+/Hi8TJQW9Ub+Rxk/8OgFl4arl2sfNmi0r9FVB6cUUNKQeMTy5BxMpEPVLcsLAeOoqkB6xXPmDk8Xs5gCs+Crup1+0f4Ds1BFadur2BUNzNqynMOphDhj72eknfpwzcTNMwTg369zdwU9eZ+eehfq/0fcVagwxwghXg==
vkdjzJwr9+Ff5bnPWWb6qzSjEyImYBVBRl5Pgd8JlLr+yyP1tusQijk86Yob2g0ABxv5sBJC9rM5MK1Dke4ah1fS/bKqv2AgXrW+7YIqN8wM/sBV52zUkwhlW/Juf941HsvfHo8llhGOCzin6pJm8ZwoFHnYiXBiUAB70sDW5VxJGtUMNH/qyxpQj/kPrcjlgk913j0bmOOLirmy030B2oVNaiBZsNX+ceWHhoBH6rqMTL0NkMmY4UFxgz0GYifSxAa8N8E+xrecpPX+1EJZJQ==
uBEVKVwDFaweK/+e6C5sjaKkH7FlAva80ZFQlMIsVnKJ05yIr5X48Co249czRxRcClohaWdniUADAACfbqE+JceUoN9vEq9GsmfbEiBYcLo=
空异常
H4CKR9rkWWMhOSi5p5Td/QqEv/WF6Brzj0b8MsxmaGE=
- lfgF/cg+n9V7dHr2qli10pgS4MDZzKeWn/Qm0unxF8tieLZgg6rNrPZd6aSwFK2lnxQyvjloSJrnJjN/N+9ySVyIh4tz7aMxO55RREdBQU4hYVVY+3asFx3GvY66NVi7l+eU4vZtq0SZ+fUTsRD975uR4EYHaheO3uUXYOaW5GDDVtEAF1Vif6fFhTfvv7RTup1vCQI0DyVblV2HgW0EvMjWGl5/glXiW3G97nZaQzG1bQ0fqRhq0ukecgtX33faQxhx2XaQukVOUqRmXltKRnTzjVS4pYUk3w0Exe3kPQBI3qALWs/L9dAt0xULO0Fou/DjkVf2A0vZpI6XanvLnyBHRVjwnqYODSiZUHYS0AGA9Sx1a8SXATGf0LLG3w8B/9+/cwcS90BIzLKKnrdIRYHd6zgo1p3shi3Z7Sy3dOtBxmzUwluGQxkIfNd6pjkl
示例
dnC4C79+++7hmkZ7ssvw89JrSNmDkaJtS4QrD0hl7lPsoSK64NsyIAwpTsYzjKEQoQx+RNcxkbnFkUD5LgnrW9FPvdBXaHUMU8Ru/61AyNDRJteSJ4oJx/e9V+MIGIHo
/*eslint space-in-parens: ["error", "never", { "exceptions": ["{}"] }]*/
foo({bar: 'baz'});
foo(1, {bar: 'baz'});
dnC4C79+++7hmkZ7ssvw89JrSNmDkaJtS4QrD0hl7lPsoSK64NsyIAwpTsYzjKEQoQx+RNcxkbnFkUD5LgnrW6ObreNrPCAeDF9WuS37PVXypDPu1rWyKHeedVedvV8A
/*eslint space-in-parens: ["error", "never", { "exceptions": ["{}"] }]*/
foo( {bar: 'baz'} );
foo(1, {bar: 'baz'} );
dnC4C79+++7hmkZ7ssvw8/o3sEMEzN6a7NJpPN7h+x8NBsOhB1Sdc80U9XWOWAaLkvneMt/OHXK22p1EzK3JIl5+qEFelWQMqHAZY6LjWd1x4SjY9CMOkPLM4afXgBDE
/*eslint space-in-parens: ["error", "always", { "exceptions": ["{}"] }]*/
foo( {bar: 'baz'} );
foo( 1, {bar: 'baz'} );
dnC4C79+++7hmkZ7ssvw8/o3sEMEzN6a7NJpPN7h+x8NBsOhB1Sdc80U9XWOWAaLkvneMt/OHXK22p1EzK3JIjx/LUPFmjT3Uc+6+VljxflQEmXj+aUXcsLYNmbUAmrV
/*eslint space-in-parens: ["error", "always", { "exceptions": ["{}"] }]*/
foo({bar: 'baz'});
foo( 1, {bar: 'baz'});
dnC4C79+++7hmkZ7ssvw89JrSNmDkaJtS4QrD0hl7lPsoSK64NsyIAwpTsYzjKEQwiznxoMbQJ+j2BclqyKB9da+PYTZ+wjwz2vGzXU5H616yx8aZM/1KZTiSiZMVFrT
/*eslint space-in-parens: ["error", "never", { "exceptions": ["[]"] }]*/
foo([bar, baz]);
foo([bar, baz], 1);
dnC4C79+++7hmkZ7ssvw89JrSNmDkaJtS4QrD0hl7lPsoSK64NsyIAwpTsYzjKEQwiznxoMbQJ+j2BclqyKB9SxxMwF+zo9nOTC3iK53QVwRwjoBbvc0hTwqXUQF/h0W
/*eslint space-in-parens: ["error", "never", { "exceptions": ["[]"] }]*/
foo( [bar, baz] );
foo( [bar, baz], 1);
dnC4C79+++7hmkZ7ssvw8/o3sEMEzN6a7NJpPN7h+x8NBsOhB1Sdc80U9XWOWAaLD70b95e7gDM+9TSz1dO4zBRUy3gAGRbHvnHwmJfOFL15eK0V7Aj2ngFCKBfgS87c
/*eslint space-in-parens: ["error", "always", { "exceptions": ["[]"] }]*/
foo( [bar, baz] );
foo( [bar, baz], 1 );
dnC4C79+++7hmkZ7ssvw8/o3sEMEzN6a7NJpPN7h+x8NBsOhB1Sdc80U9XWOWAaLD70b95e7gDM+9TSz1dO4zMECzsbD/s0ZDT1w/7QlwPBj/M4+MV3honuz4t5r/tRA
/*eslint space-in-parens: ["error", "always", { "exceptions": ["[]"] }]*/
foo([bar, baz]);
foo([bar, baz], 1 );
dnC4C79+++7hmkZ7ssvw89JrSNmDkaJtS4QrD0hl7lPsoSK64NsyIAwpTsYzjKEQsngMqvdHTv6/6vtaxayyFkDRtXFAcIqzjW1Ztbt82hSamS3uBW5rMQSbNW5A7Bia
/*eslint space-in-parens: ["error", "never", { "exceptions": ["()"] }]*/
foo((1 + 2));
foo((1 + 2), 1);
foo(bar());
dnC4C79+++7hmkZ7ssvw89JrSNmDkaJtS4QrD0hl7lPsoSK64NsyIAwpTsYzjKEQsngMqvdHTv6/6vtaxayyFlO+zjpAUM3AaYtcmLqZfpXQPWVP3NVqRmmizhnyOwy8
/*eslint space-in-parens: ["error", "never", { "exceptions": ["()"] }]*/
foo( (1 + 2) );
foo( (1 + 2), 1);
foo(bar() );
dnC4C79+++7hmkZ7ssvw8/o3sEMEzN6a7NJpPN7h+x8NBsOhB1Sdc80U9XWOWAaLVHnC4fCNY7ALOa5tO8uewICRVtEwELaMN345OzJUbr7IQw591mO2InEMTfmQ/IEU
/*eslint space-in-parens: ["error", "always", { "exceptions": ["()"] }]*/
foo( ( 1 + 2 ) );
foo( ( 1 + 2 ), 1 );
dnC4C79+++7hmkZ7ssvw8/o3sEMEzN6a7NJpPN7h+x8NBsOhB1Sdc80U9XWOWAaLVHnC4fCNY7ALOa5tO8uewKDz26DKi/puMjjngFuMYIL7Rw5lUYWUzRWWbYNZlDGM
/*eslint space-in-parens: ["error", "always", { "exceptions": ["()"] }]*/
foo(( 1 + 2 ));
foo(( 1 + 2 ), 1 );
pcgGrcT6ehN81I7tnO8FfE3ow9D8MtbHyZhQ0NxVdYg/0ZJFKMDopkWAQD0O6GPXeAreWSOp7CU+9mKxZiEmhySxoUlQyNcD+T0iGkOApFatF1O3Nj+PYFKH4j9heKjKYXuD46h+ytIZbVUePVGHyc2mWofbVL4tMmsysOungRo=
fQ1AlySJBvKwq2O/zaQ3XcPGbt08OTfridkF++gbRunLBVcvKWtFzKorAzQt+b3Jp2Yj0r7OH4a5KG7euqFSVU+5nyewpZZKSZDDzTycXJ5K//EyKQvgYqxqOEDlb9lAilxCfSvLaSo4GWhEE6IyQw==
/*eslint space-in-parens: ["error", "never", { "exceptions": ["empty"] }]*/
foo();
dnC4C79+++7hmkZ7ssvw89JrSNmDkaJtS4QrD0hl7lPsoSK64NsyIAwpTsYzjKEQPcL22XArMadud1Lh5BsjC3plqku+iHodhz5b7mAQIvwCY+R3x9hZAiBa61HPLWYOfQm/o91Jbq4vR4Hgz6zFKw==
/*eslint space-in-parens: ["error", "never", { "exceptions": ["empty"] }]*/
foo( );
iDZsplpYGzDeVJf8SpCiX7QRZsWNaPqkL1Z2SDgjlezWG+/4V7nxOvVPFPzA3shITigWGCe4T45D2NUrG7q/fRtFkFcCkzzp+0MtsUjZWjck85nSOyr0J17JST8gt/FvkI3kwG4KwcRei0B+ny0DbQ==
/*eslint space-in-parens: ["error", "always", { "exceptions": ["empty"] }]*/
foo( );
dnC4C79+++7hmkZ7ssvw8/o3sEMEzN6a7NJpPN7h+x8NBsOhB1Sdc80U9XWOWAaLq6hfR6xxBW3nWBh+PaEnwiw2gQFwXIWJY1ylfxMepTZj8uQdl79ZD9js1cOTK/Gd/5mOQSorLhqrx863Yo1hgQ==
/*eslint space-in-parens: ["error", "always", { "exceptions": ["empty"] }]*/
foo();
fcAdnWBtFwR0CTrAsociHuqixdsd7ZBhdE8zS8z2lbuDvc3IXV2PN0LoAB8yo/+DlCykkquJEibb4QtluYwZ+Adiv9BJTW0QyaP56E9HKqQ=
dnC4C79+++7hmkZ7ssvw8/o3sEMEzN6a7NJpPN7h+x8NBsOhB1Sdc80U9XWOWAaL/PZCUbbw3tMaLZ84fjACTqLDQlIHlDbWr3kLmu6beVOG+K51rPxZC6bNTx4TxZw/Y68M53JUnBXcj9OHjnn0/w==
/*eslint space-in-parens: ["error", "always", { "exceptions": ["{}", "[]"] }]*/
bar( {bar:'baz'} );
baz( 1, [1,2] );
foo( {bar: 'baz'}, [1, 2] );
dnC4C79+++7hmkZ7ssvw8/o3sEMEzN6a7NJpPN7h+x8NBsOhB1Sdc80U9XWOWAaL/PZCUbbw3tMaLZ84fjACTqLDQlIHlDbWr3kLmu6beVO7gmhugNlGgkFHI22LSrmXDPcjW8nuysAzLuRoLyYNxA==
/*eslint space-in-parens: ["error", "always", { "exceptions": ["{}", "[]"] }]*/
bar({bar:'baz'});
baz( 1, [1,2]);
foo({bar: 'baz'}, [1, 2]);
何时不使用
VbhtQRAJpPlzy6JW+/kv67ZEyoUYBg5MdjDlVeP8pIxrYxilrMpVk1CsPLQTgiCmqK+dFThm6/roQfkXS4ooYoQ/L/OG9sTb39/7gzNyo8E=