ESLint:eslintrc 中的意外 属性 "indent"

ESLint: Unexpected property "indent" in eslintrc

如文档所述here,有一个名为 indent 的用于缩进的 ESLint 属性。该示例如下所示:

Or for tabbed indentation:

{
    "indent": ["error", "tab"]
}

但是,如果我将这段确切的代码粘贴到我的 .eslintrc 文件中,VS Code 会将其显示为错误:

ESLint: ESLint configuration in .eslintrc is invalid: - Unexpected top-level property "indent". . Please see the 'ESLint' output channel for details.

我之前的.eslintrc文件已经有很多规则,并且没有打印出错误。如果我将 "indent" 添加到该列表,或者单独添加,它会失败。

这是在 VS Code 的 ESLint 输出通道中打印的错误和堆栈跟踪:

[Error - 10:38:55 PM] ESLint stack trace:
[Error - 10:38:55 PM] Error: ESLint configuration in .eslintrc is invalid:
    - Unexpected top-level property "indent".
    at validateConfigSchema (/home/aaronfranke/workspace/OddJobs/node_modules/eslint/lib/shared/config-validator.js:286:15)
    at ConfigArrayFactory._normalizeConfigData (/home/aaronfranke/workspace/OddJobs/node_modules/eslint/lib/cli-engine/config-array-factory.js:469:9)
    at ConfigArrayFactory._loadConfigDataInDirectory (/home/aaronfranke/workspace/OddJobs/node_modules/eslint/lib/cli-engine/config-array-factory.js:445:33)
    at ConfigArrayFactory.loadInDirectory (/home/aaronfranke/workspace/OddJobs/node_modules/eslint/lib/cli-engine/config-array-factory.js:401:18)
    at CascadingConfigArrayFactory._loadConfigInAncestors (/home/aaronfranke/workspace/OddJobs/node_modules/eslint/lib/cli-engine/cascading-config-array-factory.js:305:46)
    at CascadingConfigArrayFactory.getConfigArrayForFile (/home/aaronfranke/workspace/OddJobs/node_modules/eslint/lib/cli-engine/cascading-config-array-factory.js:250:18)
    at CLIEngine.executeOnText (/home/aaronfranke/workspace/OddJobs/node_modules/eslint/lib/cli-engine/cli-engine.js:860:47)
    at /home/aaronfranke/.vscode/extensions/dbaeumer.vscode-eslint-1.9.1/server/out/eslintServer.js:1:60107
    at /home/aaronfranke/.vscode/extensions/dbaeumer.vscode-eslint-1.9.1/server/out/eslintServer.js:1:61116

这是怎么回事?这个选项不知何故无效吗?示例配置错误吗?我的 ESLint extension 有问题吗? VS Code 有问题吗?我正在使用 Ubuntu 18.04 Linux 64 位 VS Code 1.40.1,ESLint 扩展 1.9.1,eslint --versionv5.16.0.

不允许将此设置放在顶层属性,这意味着它必须嵌套在另一个属性,即"rules"。所以你必须这样写:

{
    //... other stuff ...

    "rules": {
        "indent": [ "error", "tab" ]
    }
}