最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论