ESLint no-multi-spaces allow within object declaration

ESLint no-multi-spaces allow within object declaration

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

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

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

In the documentation it is stated:

The easiest way to determine the node types for exceptions is to use the 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 } }] */

如果可行,请告诉我。