简体   繁体   English

是否有用于数组多行检查的 eslint 规则?

[英]Is there eslint rule for array multiline checking?

I need to add eslint rule for the following case:我需要为以下情况添加 eslint 规则:

// 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? eslint 中是否有这样的规则,或者我怎么能完成它?

As far as I know there are no eslint rules for that.据我所知,没有 eslint 规则。 But there are proposals for array-bracket-newline and array-element-newline .但是有关于array-bracket-newlinearray-element-newline

If you want to try JSCS, it already has a rule validateNewlineAfterArrayElements which can be configured as below:如果你想尝试 JSCS,它已经有一个规则validateNewlineAfterArrayElements可以配置如下:

"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. ,这也是我的建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM