[英]Eslint parse error on comma dangle in functions
I couldn't find an answer to this question on SO (it might be there, I just couldn't find it), so I'm posting the question and the answer I finally found. 我无法在SO上找到此问题的答案(可能在那里,我只是找不到它),所以我发布了问题和最终找到的答案。 I hope it helps.
希望对您有所帮助。
When using a dangling comma on function calls, ESLint throws this error: Parsing error: Unexpected token )
. 在函数调用上使用悬挂的逗号时,ESLint会引发以下错误:
Parsing error: Unexpected token )
。 The "unexpected token" is the function's closing paren. “意外令牌”是函数的结束日期。
I have comma-dangle
set to 'comma-dangle': ['error', 'always-multiline']
in my eslintrc
file. 我在
eslintrc
文件eslintrc
comma-dangle
设置为'comma-dangle': ['error', 'always-multiline']
。
Why would this error get thrown? 为什么会引发此错误?
Just to clarify, this is what a dangling comma would look like in a function call: 为了澄清,这是函数调用中悬挂的逗号的样子:
const result = parseInput(
input,
true,
paramNames, // this is the line with the dangling comma
)
Dangling commas in function calls were added in ECMAScript 2017 (yay!). 在ECMAScript 2017中添加了函数调用中的悬挂逗号(是!)。 In order for ESLint to recognize this new feature, you have to specify the
ecmaVersion
in .eslintrc
. 为了使ESLint能够识别此新功能,必须在
ecmaVersion
中指定.eslintrc
。 ECMAScript 2017 corresponds to ecmaVersion
8. So the setting would look something like this: ECMAScript 2017对应于
ecmaVersion
。因此该设置如下所示:
"parserOptions": {
"ecmaVersion": 8
}
FYI, you can use any ecmaVersion
greater than 8 as well. 仅供参考,您也可以使用任何大于8的
ecmaVersion
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.