array-bracket-spacing

在数组括号内强制保持一致的间距

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

许多样式指南要求或不允许在数组括号和其他标记之间使用空格。此规则适用于数组字面和解构赋值(ECMAScript 6)。

/*eslint-env es6*/

var arr = [ 'foo', 'bar' ];
var [ x, y ] = z;

var arr = ['foo', 'bar'];
var [x,y] = z;

规则详情

此规则强制数组括号内的间距一致。

选项

此规则有一个字符串选项:

    iNXxxdIPalTDlL+DtIlk3AhbJCEpM1U7ukPCclzu6K+k/scbGL0FYhY9u8HDxmqaJ2meajO7J4qrQrVDMJuJrWFDXPKz+LjMey99dFB2L7Fmq6S9v6Enwl1X6HU3Uha/5KSDCcSGgtBaMJtpv5U33VNCNqsgncUbiLss5efTfPLc7H3otIQQvGFXCxXEOjzqJxzy6sebnbbkJz2Jb1j+bqJX1hwa3FeIJJ4AokNCvg8=

ZmISekGbcAWtmV//14mcrLfLIAw6mxSzDDbtsWnEaXGE5XJGvOAoyprWM2tZM4zrvYkAuO4HFeRu0xi3SZ7QyOpryxJBbBujUABzj6EDZC/qLyLKdL2zQzLjdTs7apYt

    J8wTaECNecdgAyDlW+qwnZ4C0Zph50rthS9HZrD37qsOP99hGOho1TjSi55vtf/bbsifI96Yuo5c2v22SEUfwDyzOw2kYb9oR8D+fgDl9vnVUNriZVcHZQUmgbuYFeDdNmk+0gFp7iPYW+z66rm6tjoIU8g/wrdYkfhROq5xmJLyk/Ar4HvUq0SFidkn7MAwOrbC3aauG4RqDBZUZrclx1uDlqgP2NgZxlbKS4yhmsbImv5sHyeWo38Mkh9v7DU4KUjX9IXyVi2YNit4ceAdk8iYdR27dY5A0tMhsN41PKuPtVfde688yIY8z36qyfqbGXrDv5nS+EfnOB8mNN/X5Hw1FsWW0vPHTlMheVytLKcCEy5PMo2A10NCTbDMiSoZaWEh/t1F1o/n3YmLVVAu84TLYKR1PTYIbZD2YWyVGevt2SZFGBSMzczSZhoB7rTVh6t53k39YRKwuIIr+HbRUK34NE0P+BNaA2p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qGGCciGQJ7635j23Ye/yO2YKKln6aoyrg8m/6V5cBOFOLV7btndNLQg8Y9Qv9xXvKZY/6gbj7qmojaAIGEiiEuxb4lROuD5dWnQSXXOSgDQQ+2NjwyzFkTSRsWRb4XckT+0TGTJpwCSj7rgJfgclw8O//qnQ8XNdgqQnqUV98/XhKJX5CA3sMbs+e01dwnZbe++FlDtLEIkYkwV60Mr3Iy19p49dVIrEwLjG5JY3pkbOzwipRaelVyyQ4akP5pXSOF/LQ7evOXcM9S+Wv2BIp2I4VMFArlIG1teIgd9WrED+66stA==

never

6OjE+A1hvEglXN51x/s/8uUC7gyP6F6HJ0Vtiw36wdY9gvFL7TR9LUo9iuh1qNzbmyJYQLqUUMlJcLHEVRD5KpIoeJm0sSO3kQcBmWBLcUI=

/*eslint array-bracket-spacing: ["error", "never"]*/
/*eslint-env es6*/

var arr = [ 'foo', 'bar' ];
var arr = ['foo', 'bar' ];
var arr = [ ['foo'], 'bar'];
var arr = [[ 'foo' ], 'bar'];
var arr = [ 'foo',
  'bar'
];
var [ x, y ] = z;
var [ x,y ] = z;
var [ x, ...y ] = z;
var [ ,,x, ] = z;

6OjE+A1hvEglXN51x/s/8uUC7gyP6F6HJ0Vtiw36wdY9gvFL7TR9LUo9iuh1qNzb2a0Sls9/8lIPqYXkwRk0f95aWaKPTNGR+aa69xq0Le8=

/*eslint array-bracket-spacing: ["error", "never"]*/
/*eslint-env es6*/

var arr = [];
var arr = ['foo', 'bar', 'baz'];
var arr = [['foo'], 'bar', 'baz'];
var arr = [
  'foo',
  'bar',
  'baz'
];
var arr = ['foo',
  'bar'
];
var arr = [
  'foo',
  'bar'];

var [x, y] = z;
var [x,y] = z;
var [x, ...y] = z;
var [,,x,] = z;

always

7xDYtjDnSQq8pZ502SNO6rUSXeAhG44JRQMyC8lfzF0rjfjztQFoqRNg761ca1W+vlYb9H9qSbjE2cjizhSJ8pDt3WkRXtZ+R2AnNkF38Sk=

/*eslint array-bracket-spacing: ["error", "always"]*/
/*eslint-env es6*/

var arr = ['foo', 'bar'];
var arr = ['foo', 'bar' ];
var arr = [ ['foo'], 'bar' ];
var arr = ['foo',
  'bar'
];
var arr = [
  'foo',
  'bar'];

var [x, y] = z;
var [x,y] = z;
var [x, ...y] = z;
var [,,x,] = z;

7xDYtjDnSQq8pZ502SNO6rUSXeAhG44JRQMyC8lfzF2qx+Cin4ZY4h7DD32Zaey9Snt1xBtRxEQZKtjKUCFK3BFFC+UO088o8zdUEeFG7VA=

/*eslint array-bracket-spacing: ["error", "always"]*/
/*eslint-env es6*/

var arr = [];
var arr = [ 'foo', 'bar', 'baz' ];
var arr = [ [ 'foo' ], 'bar', 'baz' ];
var arr = [ 'foo',
  'bar'
];
var arr = [
  'foo',
  'bar' ];
var arr = [
  'foo',
  'bar',
  'baz'
];

var [ x, y ] = z;
var [ x,y ] = z;
var [ x, ...y ] = z;
var [ ,,x, ] = z;

singleValue

7xDYtjDnSQq8pZ502SNO6rOEdMRXiPLzTkgSI+h5Ut4jyKiAEvk84jjX7iozD914hcnyV2ACYpjuy1I0mEtZ+t3CsH7dLho6Nw2uIuVj3mUy6MaNbRpgPUQKzpRVdPw+

/*eslint array-bracket-spacing: ["error", "always", { "singleValue": false }]*/

var foo = [ 'foo' ];
var foo = [ 'foo'];
var foo = ['foo' ];
var foo = [ 1 ];
var foo = [ 1];
var foo = [1 ];
var foo = [ [ 1, 2 ] ];
var foo = [ { 'foo': 'bar' } ];

7xDYtjDnSQq8pZ502SNO6rOEdMRXiPLzTkgSI+h5Ut4jyKiAEvk84jjX7iozD914hcnyV2ACYpjuy1I0mEtZ+uLf4ubiQD++uKQR/YPmTxdjqs1F/mfzXPqTEtBdA2Ix

/*eslint array-bracket-spacing: ["error", "always", { "singleValue": false }]*/

var foo = ['foo'];
var foo = [1];
var foo = [[ 1, 1 ]];
var foo = [{ 'foo': 'bar' }];

objectsInArrays

7xDYtjDnSQq8pZ502SNO6rOEdMRXiPLzTkgSI+h5Ut4rctSH+espPJCoUIVsWrzW8fBm1NOMfebRiX34v4oxwI05eVNGQ3+M016lHMDYdjZpGdUkkIAolb2cGihpSPNmbvXsMIaH+Ve/xDxIsnXhzA==

/*eslint array-bracket-spacing: ["error", "always", { "objectsInArrays": false }]*/

var arr = [ { 'foo': 'bar' } ];
var arr = [ {
  'foo': 'bar'
} ]

7xDYtjDnSQq8pZ502SNO6rOEdMRXiPLzTkgSI+h5Ut4rctSH+espPJCoUIVsWrzW8fBm1NOMfebRiX34v4oxwN8OhqzC733GKmQuYbqBdDW/DOfen7evi+a3R1HPIvIfRik3rdCGvWTPwgOMgXQqUw==

/*eslint array-bracket-spacing: ["error", "always", { "objectsInArrays": false }]*/

var arr = [{ 'foo': 'bar' }];
var arr = [{
  'foo': 'bar'
}];

arraysInArrays

7xDYtjDnSQq8pZ502SNO6rOEdMRXiPLzTkgSI+h5Ut5ccQ0Zf4out1JO600yOHA/DMZ9uEYhiaSkxK47SJc6B1t1YJr43j0W5lCwXbKswdtiOLdhpaMQ4hqJdx9hS5I0hv8V7z3E22cuKdsmOzApsg==

/*eslint array-bracket-spacing: ["error", "always", { "arraysInArrays": false }]*/

var arr = [ [ 1, 2 ], 2, 3, 4 ];
var arr = [ [ 1, 2 ], 2, [ 3, 4 ] ];

7xDYtjDnSQq8pZ502SNO6rOEdMRXiPLzTkgSI+h5Ut5ccQ0Zf4out1JO600yOHA/DMZ9uEYhiaSkxK47SJc6B96/uJ1RQ04hf1+juH5eI6bVDc4csBF6FA//qzu25T4jU21/N7YILIwrrgwQvuySAQ==

/*eslint array-bracket-spacing: ["error", "always", { "arraysInArrays": false }]*/

var arr = [[ 1, 2 ], 2, 3, 4 ];
var arr = [[ 1, 2 ], 2, [ 3, 4 ]];

何时不使用

6C0urmKX5N4cFGCPyxiuI+dJ6YO5qI6vrx1lTWk5KylvpCufkiU7LQ6nQ5/QtI4/69lMs+IoiXIPe3dKsNAUAnXDPIkcjUupTTM/uqhSF+KgM7CN59DY9IO4MpR7F/2F