I need to add eslint rule for the following case:
// bad
[
'onClickSave',
'onClickCancel'].forEach(bind(this));
// good
[
'onClickSave',
'onClickCancel'
].forEach(bind(this));
When defining an object or array with multiple lines, brackets must be on a new line.
Is there such rule in eslint or how could I acplish it?
I need to add eslint rule for the following case:
// bad
[
'onClickSave',
'onClickCancel'].forEach(bind(this));
// good
[
'onClickSave',
'onClickCancel'
].forEach(bind(this));
When defining an object or array with multiple lines, brackets must be on a new line.
Is there such rule in eslint or how could I acplish it?
Share Improve this question asked Dec 5, 2016 at 9:40 ErikErik 14.8k49 gold badges140 silver badges223 bronze badges2 Answers
Reset to default 5As far as I know there are no eslint rules for that. But there are proposals for array-bracket-newline
and array-element-newline
.
If you want to try JSCS, it already has a rule validateNewlineAfterArrayElements
which can be configured as below:
"validateNewlineAfterArrayElements": {
"maximum": 1
}
ie, if you have more than one element in the array, each should be on a new line.
"array-element-newline": [
"error",
'always'
],
The above will ensure a newline after each array element.
Coupling with:
"array-bracket-newline": [
"error",
{
"minItems": 1,
},
],
, would be my suggestion, as well.