# Next.js: ESlint + Prettier
# Run in console
npm install --save-dev eslint prettier eslint-plugin-react eslint-plugin-react-hooks eslint-config-prettier eslint-plugin-prettier eslint-plugin-jsx-a11y eslint-plugin-simple-import-sort
touch .eslintrc.js .prettierrc
echo "node_modules" | tee .eslintignore .prettierignore
1
2
3
2
3
# .prettierrc
{
"semi": true,
"tabWidth": 2,
"singleQuote": true,
"trailingComma": "es5",
}
1
2
3
4
5
6
2
3
4
5
6
# .eslintrc.js
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
ecmaFeatures: {
jsx: true
}
},
settings: {
react: {
version: 'detect'
}
},
env: {
es6: true,
browser: true,
amd: true,
node: true
},
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:jsx-a11y/recommended',
'plugin:prettier/recommended'
],
plugins: ['simple-import-sort'],
rules: {
'prettier/prettier': ['error', {}, { usePrettierrc: true }],
rules: {
'react/react-in-jsx-scope': 'off',
'simple-import-sort/sort': 'error',
'jsx-a11y/anchor-is-valid': [
'error',
{
components: ['Link'],
specialLink: ['hrefLeft', 'hrefRight'],
aspects: ['invalidHref', 'preferButton']
}
]
}
}
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# package.json
"scripts": {
"lint": "eslint .",
"lint-fix": "eslint --fix .",
"format": "prettier --write './**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc"
},
1
2
3
4
5
2
3
4
5
Source: https://dev.to/arpit73/eslint-and-prettier-for-react-apps-bonus-next-js-and-typescript-3e46