-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
.eslintrc.js
127 lines (123 loc) · 5.43 KB
/
.eslintrc.js
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// [lock-all/] 🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫🚫
/*
* We use a JavaScript file for the .eslintrc file (instead of a JSON file) as it supports
* comments that can be used to better describe rules and allows us to write some logic.
*
* This config lints both TS and JS. Shared rules are defined below, and any additional rules specific
* to either TS or JS are specified in addition to those.
*
* For all other files types, such as JSON, you can use Prettier and turn on
* the auto format option in VS Code. You can select Prettier when running Format Document the first time in VS Code.
*
* This config uses Prettier as an ESLint rule. The advantage of having prettier setup as an
* ESLint rule using eslint-plugin-prettier is that JS and TS code can automatically be fixed using ESLint's --fix option.
* Prettier's config is defined in `.prettierrc.js`. See that file for more information.
*
* ## Automatically Fix Code in VS Code
*
* For a good developer experience, it's useful to setup your editor to automatically run ESLint's automatic
* fix command (i.e. eslint --fix) whenever a file is saved. Here is the VS Code config
* required in the settings.json file in VS Code to get automatic fixing whenever saving a file:
*
* ```
* {
* "editor.codeActionsOnSave": {
* "source.fixAll.eslint": true
* },
* }
* ```
*
* See the following post for more: https://www.robertcooper.me/using-eslint-and-prettier-in-a-typescript-project
*/
/** Rules shared by both the TS and JS lint configurations. */
const sharedTSAndJSRules = {
'react/display-name': 'off',
// Disable error about display name
'react/prop-types': 'off',
// Disable error about prop types
'react/no-unescaped-entities': 'off',
// Disable error about unescaped entities
'react-hooks/rules-of-hooks': 'error',
// Checks rules of Hooks
'react-hooks/exhaustive-deps': 'warn', // Checks effect dependencies
};
/** Rules specific to TS. */
const tsSpecificRules = {
'@typescript-eslint/no-empty-interface': 'off', // Disable empty interface error
'@typescript-eslint/no-explicit-any': 'warn', // Warn on any
'@typescript-eslint/no-unused-vars': 'warn', // Warn for unused vars
};
/** Rules specific to JS. */
const jsSpecificRules = {
'react/prop-types': 'off', // Disable error about prop types
};
module.exports = {
// Below we use the overrides array to define separate linting options for both TS and JS.
overrides: [
{
files: ['**/*.ts', '**/*.tsx'],
// TypeScript files
parser: '@typescript-eslint/parser',
// Specifies the ESLint parser for TypeScript
parserOptions: {
ecmaVersion: 2020,
// Allows for the parsing of modern ECMAScript features
sourceType: 'module',
// Allows for the use of imports
ecmaFeatures: {
jsx: true, // Allows for the parsing of JSX
},
},
extends: [
'plugin:react/recommended', // Uses the recommended rules from @eslint-plugin-react
'plugin:react-hooks/recommended', // Uses the recommended rules from @eslint-plugin-react-hooks
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from @typescript-eslint/eslint-plugin
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
'plugin:storybook/recommended', // Storybook
],
settings: {
react: {
version: 'detect', // Tells eslint-plugin-react to automatically detect the version of React to use
},
},
rules: {
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
// e.g. "@typescript-eslint/explicit-function-return-type": "off",
...sharedTSAndJSRules,
// Rules shared by both TS and JS lint configs
...tsSpecificRules, // Rules specific to TS
},
},
{
files: ['**/*.js', '**/*.jsx'],
// JavaScript files
parserOptions: {
ecmaVersion: 2020,
// Allows for the parsing of modern ECMAScript features
sourceType: 'module',
// Allows for the use of imports
ecmaFeatures: {
jsx: true, // Allows for the parsing of JSX
},
},
extends: [
'plugin:react/recommended', // Uses the recommended rules from @eslint-plugin-react
'plugin:react-hooks/recommended', // Uses the recommended rules from @eslint-plugin-react-hooks
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
'plugin:storybook/recommended', // Storybook
],
settings: {
react: {
version: 'detect', // Tells eslint-plugin-react to automatically detect the version of React to use
},
},
rules: {
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
// e.g. "@typescript-eslint/explicit-function-return-type": "off",
...sharedTSAndJSRules,
// Rules shared by both TS and JS lint configs
...jsSpecificRules, // Rules specific to JS
},
},
],
};