Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there eslint rule for array multiline checking?

Tags:

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 accomplish it?

like image 226
Erik Avatar asked Dec 05 '16 09:12

Erik


1 Answers

As 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.

like image 174
yadhu Avatar answered Sep 25 '22 16:09

yadhu