【问题标题】:YAMLException: Error: duplicated mapping key at line 45, column 30: "beforeLineComment": false,YAMLException:错误:第 45 行第 30 列重复映射键:“beforeLineComment”:false,
【发布时间】:2017-04-29 03:24:32
【问题描述】:

我正在尝试在我的根目录上将 ESLINT 与 eslint . 一起使用并遇到此错误:

YAMLException: Cannot read config file: 
/mypath/node_modules/extend/.eslintrc Error: 
duplicated mapping key at line 45, column 30:  "beforeLineComment": false,

我有节点 v6.9.1 eslint 是 v3.12.1

这是我的 .eslintrc.json 配置文件:

{
    "rules": {
        "indent": [2, 2],
        "quotes": [2, "single"],    
        "linebreak-style": [2, "unix"],
        "semi": [2, "always"],
        "no-underscore-dangle": 0,
        "curly": 0,
        "no-use-before-define": [2, "nofunc"],
        "spaced-comment": [2, "always"],
        "space-before-function-paren": [2, { "anonymous": "always", "named": "never" }],
        "space-after-keywords": [2, "always"],
        "space-before-blocks": [2, "always"],
        "semi-spacing": [2, {"before": false, "after": true}],
        "no-var": 2,
        "object-shorthand": [2, "always"],
        "prefer-const": 2
    },
    "env": {
        "es6": true,
        "node": true,
        "mocha": true
    }
}

如您所见,我使用的是 json 而非 YAML,我不知道为什么会出现该错误。

【问题讨论】:

  • 该文件甚至没有 45 行。您确定就是它抱怨的文件吗?
  • 除非指定"root": true,否则eslint会合并.eslintrc文件with files found in parent directories。也许这种合并涉及一些 YAML 转换,并且父目录中的 .eslintrc 文件中可能有一些奇怪的东西?

标签: javascript json ecmascript-6 eslint


【解决方案1】:

正如您发布的异常中所述,该错误实际上并未发生在您的配置中,而是发生在您从 node_modules/extend/.eslintrc 扩展而来的配置中(看起来已经很奇怪)。

如果你使用--debug 标志运行 eslint,你可以获得更多关于配置加载的信息。它将打印出有关 ESLint 正在加载和合并的配置文件的所有信息。这应该为您指明正确的方向,以找出谁在扩展该配置以及为什么。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-13
    • 1970-01-01
    相关资源
    最近更新 更多