I’m working on a React application and I would like to have a linter set up so that I can see all the warning/errors in the console.
The docs doesn’t say much: https://create-react-app.dev/docs/setting-up-your-editor/
I have added EXTEND_ESLINT=true
in my .env.dev
file and I have created a .eslintrc.json
file as well, with the following content (taken from the docs):
JavaScript
x
17
17
1
{
2
"eslintConfig": {
3
"extends": ["react-app", "shared-config"],
4
"rules": {
5
"additional-rule": "warn"
6
},
7
"overrides": [
8
{
9
"files": ["**/*.ts?(x)"],
10
"rules": {
11
"additional-typescript-only-rule": "warn"
12
}
13
}
14
]
15
}
16
}
17
Every rule I try to add won’t do anything, I still see no warnings in the console and on top of that if I try to run the linter from the command line:
JavaScript
1
2
1
npx eslint ./src
2
I get the following error:
JavaScript
1
3
1
ESLint configuration in .eslintrc.json is invalid:
2
- Unexpected top-level property "eslintConfig".
3
What am I missing?
Advertisement
Answer
You can either create a .eslintrc.js
file inside your src
folder, with this syntax:
JavaScript
1
15
15
1
module.exports = {
2
extends: ["react-app", "shared-config"],
3
rules: {
4
"additional-rule": "warn"
5
},
6
overrides: [
7
{
8
"files": ["**/*.ts?(x)"],
9
"rules": {
10
"additional-typescript-only-rule": "warn"
11
}
12
}
13
]
14
}
15
Or add this to your package.json
(not a .eslintrc.json file):
JavaScript
1
15
15
1
"eslintConfig": {
2
"extends": ["react-app", "shared-config"],
3
"rules": {
4
"additional-rule": "warn"
5
},
6
"overrides": [
7
{
8
"files": ["**/*.ts?(x)"],
9
"rules": {
10
"additional-typescript-only-rule": "warn"
11
}
12
}
13
]
14
}
15