array-bracket-spacing (ESLint: array-bracket-spacing)
enforce consistent spacing inside array brackets
A number of style guides require or disallow spaces between array brackets and other tokens. This rule applies to both array literals and destructuring assignments (ECMAScript 6).
The rule takes one or two options. The first is a string, which can be:
"never"
(default) disallows spaces inside array brackets"always"
requires one or more spaces or newlines inside array brackets
The second option is an object for exceptions to the "never"
option:
"singleValue": true
requires one or more spaces or newlines inside brackets of array literals that contain a single element"objectsInArrays": true
requires one or more spaces or newlines between brackets of array literals and braces of their object literal elements[ {
or} ]
"arraysInArrays": true
requires one or more spaces or newlines between brackets of array literals and brackets of their array literal elements[ [
or] ]
When using the "always"
option the second option takes on these exceptions:
"singleValue": false
disallows spaces inside brackets of array literals that contain a single element"objectsInArrays": false
disallows spaces between brackets of array literals and braces of their object literal elements[ {
or} ]
"arraysInArrays": false
disallows spaces between brackets of array literals and brackets of their array literal elements[ [
or] ]
This rule has build-in exceptions:
"never"
(and also the exceptions to the"always"
option) allows newlines inside array brackets, because this is a common pattern"always"
does not require spaces or newlines in empty array literals[]
"array-bracket-spacing": [true, "always"]
"array-bracket-spacing": [true, "never"]
"array-bracket-spacing": [true, "never", {
"arraysInArrays": true
}]
{
"anyOf": [
{
"type": "array",
"items": [
{
"enum": [
"always",
"never"
]
}
],
"minItems": 0,
"maxItems": 1
},
{
"type": "object",
"properties": {
"singleValue": {
"type": "boolean"
},
"objectsInArrays": {
"type": "boolean"
},
"arraysInArrays": {
"type": "boolean"
}
},
"additionalProperties": false
}
]
}