【问题标题】:Eslint parse error on comma dangle in functions函数中逗号悬挂的 Eslint 解析错误
【发布时间】:2019-01-21 23:36:48
【问题描述】:

我在 SO 上找不到这个问题的答案(它可能在那里,我只是找不到),所以我发布了这个问题和我最终找到的答案。希望对你有帮助。

在函数调用中使用悬空逗号时,ESLint 会抛出此错误:Parsing error: Unexpected token )。 “意外标记”是函数的结束括号。

我在我的eslintrc 文件中将comma-dangle 设置为'comma-dangle': ['error', 'always-multiline']

为什么会抛出这个错误?

澄清一下,这是一个悬空逗号在函数调用中的样子:

const result = parseInput(
  input,
  true,
  paramNames, // this is the line with the dangling comma
)

【问题讨论】:

    标签: javascript eslint


    【解决方案1】:

    在 ECMAScript 2017 中添加了函数调用中的悬空逗号(耶!)。为了让 ESLint 识别这个新特性,你必须在 .eslintrc 中指定 ecmaVersion。 ECMAScript 2017 对应于ecmaVersion 8。所以设置看起来像这样:

    "parserOptions": {
      "ecmaVersion": 8
    }
    

    仅供参考,您也可以使用任何大于 8 的 ecmaVersion

    【讨论】:

      猜你喜欢
      • 2017-10-11
      • 2019-12-25
      • 2017-04-29
      • 2014-02-03
      • 2016-03-11
      • 2020-11-30
      • 1970-01-01
      • 2021-06-10
      • 1970-01-01
      相关资源
      最近更新 更多