Error: Unexpected top-level property "$schema"
See original GitHub issueTell us about your environment
- ESLint Version: 6.0.1
- Node Version: 10.15.0
- npm Version: 6.4.1
What parser (default, Babel-ESLint, etc.) are you using? @typescript-eslint/parser
Please show your full configuration:
{
"$schema": "http://json.schemastore.org/eslintrc",
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"parserOptions": {
"project": "./tsconfig.json"
},
"rules": {
"@typescript-eslint/restrict-plus-operands": "error"
}
}
What did you expect to happen?
The $schema
field is the standard way to tell editors where to find schema for a JSON file. Without this field, IntelliSense won’t be available when people edit the .eslint.json config file.
The $schema
field is documented in the JSON Schema spec:
https://json-schema.org/latest/json-schema-core.html#rfc.section.7
What actually happened? Please include the actual, raw output from ESLint.
It appears that when ESLint validates the .eslint.json file, it rejects the $schema
field. It prints this error:
Error: ESLint configuration in .eslintrc.json is invalid:
- Unexpected top-level property "$schema".
at validateConfigSchema (D:\GitRepos\eslint-test\node_modules\eslint\lib\shared\config-validator.js:286:15)
at ConfigArrayFactory._normalizeConfigData (D:\GitRepos\eslint-test\node_modules\eslint\lib\cli-engine\config-array-factory.js:469:9)
at ConfigArrayFactory._loadConfigDataInDirectory (D:\GitRepos\eslint-test\node_modules\eslint\lib\cli-engine\config-array-factory.js:445:33)
at ConfigArrayFactory.loadInDirectory (D:\GitRepos\eslint-test\node_modules\eslint\lib\cli-engine\config-array-factory.js:401:18)
at CascadingConfigArrayFactory._loadConfigInAncestors (D:\GitRepos\eslint-test\node_modules\eslint\lib\cli-engine\cascading-config-array-factory.js:304:46)
at CascadingConfigArrayFactory.getConfigArrayForFile (D:\GitRepos\eslint-test\node_modules\eslint\lib\cli-engine\cascading-config-array-factory.js:249:18)
at FileEnumerator._iterateFilesRecursive (D:\GitRepos\eslint-test\node_modules\eslint\lib\cli-engine\file-enumerator.js:408:49)
at _iterateFilesRecursive.next (<anonymous>)
at FileEnumerator.iterateFiles (D:\GitRepos\eslint-test\node_modules\eslint\lib\cli-engine\file-enumerator.js:254:49)
at iterateFiles.next (<anonymous>)
Are you willing to submit a pull request to fix this bug?
Yes. The simplest fix is for ESLint to delete the $schema
field after it loads the file.
If people agree that we should fix this, I’m happy to create the PR.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:10 (4 by maintainers)
Top GitHub Comments
I don’t think we would specifically support
$schema
, but I wonder if we could have a whitelist of extra keys we will allow but ignore, and maybe we could add that key to such a list.I would be okay with evaluating a proposal along those lines in a new issue.
It’s a pretty cool feature! You get tab completion when typing:
…and error-underlining if you type it wrong:
…and documentation tooltips when you mouse over a setting:
The editor obtains this information by downloading the schema (e.g. http://json.schemastore.org/eslintrc) that it discovers from the
$schema
field.