gpt4 book ai didi

javascript - ESLint 对象声明内不允许使用多个空格

转载 作者:行者123 更新时间:2023-12-02 14:58:24 25 4
gpt4 key购买 nike

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

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

默认情况下,它会提示内容之前的空格。我想我需要向异常(exception)添加一个 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 } }] */

请告诉我这是否有效。

关于javascript - ESLint 对象声明内不允许使用多个空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35607626/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com