Below you see my .eslintrc file, which contains the rule that needs to be applied to a .json file.
{
"extends": "eslint:remended",
"parser": "babel-eslint",
"env": {
"browser": true,
"node": true,
"jquery": true,
"jasmine": true
},
"plugins": [
"json"
],
"rules": {
"camelcase": 2
}
The rule works literally everywhere in the project, except the .json files.
I have tried to use the "eslint-plugin-json" and couple of other modules, but they simply just don't work.
Please don't give solutions such as "use jsonlint instead, or etc.", the module for linting in the project is eslint.
Below you see my .eslintrc file, which contains the rule that needs to be applied to a .json file.
{
"extends": "eslint:remended",
"parser": "babel-eslint",
"env": {
"browser": true,
"node": true,
"jquery": true,
"jasmine": true
},
"plugins": [
"json"
],
"rules": {
"camelcase": 2
}
The rule works literally everywhere in the project, except the .json files.
I have tried to use the "eslint-plugin-json" and couple of other modules, but they simply just don't work.
Please don't give solutions such as "use jsonlint instead, or etc.", the module for linting in the project is eslint.
Share Improve this question edited Feb 15, 2019 at 14:24 Sth asked Feb 15, 2019 at 13:30 SthSth 5421 gold badge10 silver badges22 bronze badges2 Answers
Reset to default 3If I understand correctly, JSON files have not valid JavaScript syntax in most cases: outer curly brackets {}
are parsed as a block with statements and parsing error Unexpected token :
happens on the first key: value
pair. So I am not sure if this can be achieved with ESLint (ESLint checks JavaScript per definition).
You can try something like echo "(`cat test.json`)" | eslint --stdin
though.
However, camelcase
particularly cannot be applied here: ESlint seems to ignore quoted keys and you cannot use unquoted keys in JSON.
I made an alternative to eslint-plugin-json
since it didn't work for me and didn't have auto-fixing - eslint-plugin-json-format
It will also (optionally) sort your package.json for you
eslint --ext .json,.js . --fix