Search code examples
visual-studio-codeeslintindentationeslintrc

ESLint: Unexpected property "indent" in eslintrc


As documented here, there is an ESLint property for indentation called indent. The example looks like this:

Or for tabbed indentation:

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

However, if I paste this exact code into my .eslintrc file, VS Code shows this as an error:

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

The .eslintrc file that I had before has a number of rules already, and there are no errors printed with those. If I add "indent" to that list, or by itself, it fails.

Here is the error and stack trace printed in the ESLint output channel in VS Code:

[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

What's going on? Is this option not valid somehow? Is the example config wrong? Is there something wrong with my ESLint extension? Is there something wrong with VS Code? I'm using Ubuntu 18.04 Linux 64-bit with VS Code 1.40.1, ESLint extension 1.9.1, and eslint --version is v5.16.0.


Solution

  • It is not allowed to put this settings as a top level property, which means it has to be nested in another property, which is "rules". So you have to write it like this:

    {
        //... other stuff ...
    
        "rules": {
            "indent": [ "error", "tab" ]
        }
    }