ESLint无多个空格允许在对象声明中

时间:2016-02-24 16:27:49

标签: javascript eslint

如何配置no-multi-spaces规则以允许以下内容:

var arr = [
    {id: 'abc',    content: 'foo'},
    {id: 'cdefgh', content: 'bar'}
];

默认情况下,它会在content之前抱怨空格。我想我需要向exceptions添加一个AST节点,但我不知道哪个。

1 个答案:

答案 0 :(得分:2)

In the documentation it is stated

  

确定例外节点类型的最简单方法是使用online demo

所以我继续把你的代码放在那里并得到了AST。以下部分似乎是相关的部分:

{
  "type": "ObjectExpression",
  "start": 16,
  "end": 46,
  "properties": [
    {
      "type": "Property",
      "start": 17,
      "end": 26,
      "key": {
        "type": "Identifier",
        "start": 17,
        "end": 19,
        "name": "id"
      },
      "value": {
        "type": "Literal",
        "start": 21,
        "end": 26,
        "value": "abc",
        "raw": "'abc'"
      },
      "kind": "init"
    },
    {
      "type": "Property",
      "start": 31,
      "end": 45,
      "key": {
        "type": "Identifier",
        "start": 31,
        "end": 38,
        "name": "content"
      },
      "value": {
        "type": "Literal",
        "start": 40,
        "end": 45,
        "value": "foo",
        "raw": "'foo'"
      },
      "kind": "init"
    }
  ]
},

由于你的代码似乎与整个对象有关,我猜你所寻求的AST节点是ObjectExpression

/* eslint no-multi-spaces: [2, { exceptions: { "ObjectExpression": true } }] */

如果有效,请告诉我。