javascript - Is there eslint rule for array multiline checking? - Stack Overflow

I need to add eslint rule for the following case: bad['onClickSave','onClickCancel�

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 badges
Add a ment  | 

2 Answers 2

Reset to default 5

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.

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745126775a4612735.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信