This repository has been archived by the owner on Aug 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy path.eslintrc.js
255 lines (241 loc) · 8.12 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
module.exports = {
// Ignore eslintrc.js files in parent directories.
root: true,
// Use a parser compatible with TypeScript.
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
'react-hooks',
'prettier', // Ensures compatibility with Prettier.
'mui-unused-classes', // Prevents unused classes in makeStyles.
'import', // Special rules to clean up and standardize imports.
// 'unicorn', // Various awesome rules.
'react-redux', // Various rules to enforce best practices for react-redux.
'lodash', // Various rules to enforce best practices for lodash.
],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
// 'airbnb',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
'prettier',
'prettier/@typescript-eslint',
// 'plugin:unicorn/recommended',
'plugin:react-redux/recommended',
'plugin:lodash/recommended',
],
settings: {
react: {
version: 'detect',
},
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
'import/resolver': {
typescript: {
alwaysTryTypes: true, // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
project: '.',
},
},
},
env: {
es6: true,
browser: true,
jest: true,
node: true,
},
rules: {
/**
* Set up basic formatting rules with the Prettier plugin.
* This helps maintain a consistent code style.
*/
'prettier/prettier': ['warn'],
/**
* Add a warning for unused variables, except if they start with '_'.
* This flags the variable as 'unused, but potentially used in future'.
*/
'@typescript-eslint/no-unused-vars': [
'warn',
{
varsIgnorePattern: '_.*', // Prefix variables you know will be unused with an underscore.
argsIgnorePattern: '_.*', // Prefix arguments you know will be unused with an underscore.
},
],
/**
* Adds a warning when a module export is not used within the project.
*/
// TODO: Turn this on.
'import/no-unused-modules': ['off', { unusedExports: true }],
/**
* NextJS defaults.
*/
'react/react-in-jsx-scope': ['off'],
'react/display-name': ['off'],
'react/prop-types': ['off'],
'@typescript-eslint/explicit-function-return-type': ['off'],
'@typescript-eslint/explicit-member-accessibility': ['off'],
'@typescript-eslint/indent': ['off'],
'@typescript-eslint/member-delimiter-style': ['off'],
'@typescript-eslint/no-explicit-any': ['off'],
'@typescript-eslint/no-var-requires': ['off'],
'@typescript-eslint/no-use-before-define': ['off'],
/**
* Enable TypeScript checking.
*/
'@typescript-eslint/explicit-module-boundary-types': ['warn'],
/**
* Allow use of console commands at specific log levels.
* Instances of console.log and console.info should be stripped.
*/
'no-console': ['warn', { allow: ['warn', 'error', 'debug'] }],
/**
* Configure custom import sorting.
* 1. node "builtin" modules
* 2. "external" modules
* 3. "internal" modules
* 4. modules from a "parent" directory
* 5. "sibling" modules from the same or a sibling's directory
* 6. "index" of the current directory
* 7. "object"-imports (only available in TypeScript)
*/
'import/order': [
'warn',
{
alphabetize: {
order: 'asc' /* sort in ascending order. Options: ['ignore', 'asc', 'desc'] */,
caseInsensitive: true /* ignore case. Options: [true, false] */,
},
},
],
// 'sort-imports': [ 'error', { ignoreDeclarationSort: true, }, ],
/**
* Prohibit imports via relative paths.
*/
'no-restricted-imports': [
'error',
{
patterns: [
'../**/*', // No relative imports.
'./**/*', // No relative imports.
'**/index', // Don't import the index explicitly.
'src/components/util/*', // Import only the index Util module.
'!./*',
],
},
],
/**
* Enforce Rules of Hooks.
*
* @see: https://github.com/facebook/react/blob/c11015ff4f610ac2924d1fc6d569a17657a404fd/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js
*/
'react-hooks/rules-of-hooks': 'error',
/**
* Use Pascal file name casing where applicable.
* Ignores index.js because that can't be renamed.
*
* @see: https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/filename-case.md
*/
/*
'unicorn/filename-case': [
'warn',
{
case: 'pascalCase',
ignore: [
/^next\.config\.js$/,
/^next-i18next\.config\.js$/,
/^\.eslintrc\.js$/, // Ignore config files.
/\.md$/, // Ignore markdown files.
],
},
],
*/
/**'
* Using complete words results in more readable code.
* Not everyone knows all your abbreviations. Code is written only once, but read many times.
*
* @see: https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prevent-abbreviations.md
*/
/*
'unicorn/prevent-abbreviations': [
'warn',
{
replacements: {
props: false,
},
ignore: ['i18n'],
},
],
*/
/**
* There are reasons to eliminate nulls from your code completely,
* but this has issues with React (for example, a functional component can't return undefined).
*
* @see: https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-null.md
*/
//'unicorn/no-null': ['off'],
/**
* There are reasons to use the for...of block, but I prefer Lodash's method.
*/
//'unicorn/no-array-for-each': ['off'],
/**
* Use the lodash equivalent method wherever possible.
* Compared to native methods, lodash methods are always available, have better performance,
* and always have the same output.
*/
'lodash/prefer-lodash-method': ['error'],
/**
* Enforce usage of 'import _ from lodash' rather than importing members.
* A Babel plugin is installed to transpile this and enable tree shaking.
*/
'lodash/import-scope': ['warn', 'full'],
/**
* Make less severe/important issues throw warnings instead of breaking the program.
* Don't add stuff here if it can be autofixed.
*/
'mui-unused-classes/unused-classes': ['warn'],
'react/self-closing-comp': ['warn'],
'object-shorthand': ['warn'],
'react/jsx-boolean-value': ['warn'],
/**
* Turn off annoying rules I don't like.
*/
'react/jsx-filename-extension': ['off'], // Tried to turn this on but babel-plugin-root-import complains.
'no-underscore-dangle': ['off'], // Allow dangling underscores in identifier names.
'no-case-declarations': ['off'], // Allow variables to be declared in case blocks.
'import/prefer-default-export': ['off'], // Allow single exports in files. They may get more later.
'import/no-dynamic-require': ['off'], // Dynamic requires are used to reference images.
'global-require': ['off'], // Local requires are used to reference images.
'react/jsx-props-no-spreading': ['off'], // I don't mind passing spread properties using {...other} in JSX.
'max-classes-per-file': ['off'], // I don't mind having multiple classes in one file, to keep them organized.
'react-hooks/exhaustive-deps': ['off'],
},
/**
* Allow overriding the above rules for specific file path globs.
*/
overrides: [
{
files: ['*.test.js'],
rules: {
'no-restricted-imports': 'off',
},
},
{
files: ['pages/*.js', 'pages/*.ts', 'pages/*.tsx'],
rules: {
//'unicorn/filename-case': 'off',
},
},
{
files: ['packages/*.js', 'packages/*.ts', 'packages/**/*.js', 'packages/**/*.ts'],
rules: {
//'unicorn/filename-case': 'off',
'lodash/prefer-lodash-method': 'off',
'lodash/prefer-lodash-typecheck': 'off',
},
},
],
};