-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eslintrc.js
305 lines (261 loc) · 9.52 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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
// ESLint config - most of this file is taken from the config on one of Riso's previous projects in Vacuumlabs.
// EDIT: vela kokocin asi. snazme sa pouzivat co najviac extendovanych configov a co najmenej explicitnych rules
// eslint-disable-next-line @typescript-eslint/no-require-imports
const restrictedGlobals = require('confusing-browser-globals')
module.exports = {
env: {
browser: true,
es2021: true,
node: true,
},
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 12,
sourceType: 'module',
},
plugins: [
'@typescript-eslint/eslint-plugin',
'eslint-comments',
'filenames',
'no-secrets',
'node',
'unicorn',
'simple-import-sort',
],
extends: [
// for what's included, check: https://github.com/vercel/next.js/blob/canary/packages/eslint-config-next/index.js
'next',
// Baseline configurations
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
// 'plugin:@typescript-eslint/strict',
// Disable ESLint rules conflicting with Prettier
'prettier',
'prettier/prettier',
// Set rules for module imports/exports
'plugin:import/errors',
'plugin:import/warnings',
// Avoid common errors related to Promises
'plugin:promise/recommended',
// Detect common patterns that can lead to security issues
'plugin:security/recommended-legacy',
// Run Prettier as an ESLint plugin (not separately after ESLint)
'plugin:prettier/recommended',
// React-specific rules - not needed, included in 'next'
// 'plugin:react/recommended',
// 'plugin:react-hooks/recommended',
],
settings: {
react: {
version: 'detect',
},
},
rules: {
// as of React 17, React doesn't need to be imported to use JSX
'react/jsx-uses-react': 'off',
'react/react-in-jsx-scope': 'off',
// we use TS, not prop types
'react/prop-types': 'off',
// restrict usage of confusing global variables
'no-restricted-globals': ['error', ...restrictedGlobals],
// additional React rules not included in recommended set
'react/self-closing-comp': 'error',
'@typescript-eslint/ban-ts-comment': 'warn',
'@typescript-eslint/no-unused-vars': ['warn', {argsIgnorePattern: '^_', ignoreRestSiblings: true}],
'@typescript-eslint/no-explicit-any': 'warn',
// Use === instead of == for everything, except for comparison with null and other special
// cases.
eqeqeq: ['warn', 'smart'],
// Disable eval() and equivalents, as they're potentially unsafe
'no-eval': 'warn',
'no-implied-eval': 'warn',
// Use const for declaring variables when they aren't reassigned
'prefer-const': 'warn',
// Keep imports tidy: group all of them on top, order them in a conventional manner,
// add a newline after, avoid duplicates, and force a consistent style when importing index files
'import/no-absolute-path': 'error',
'import/order': 'off', // conflicts with simple-import-sort
'import/first': 'warn',
'import/newline-after-import': 'warn',
'import/no-duplicates': 'warn',
'unicorn/import-index': 'warn',
// Even better import sorting - ordering and grouping based on scope
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
// Prevent ESLint comments from accidentally disabling more rules than intended
// or masking other errors
'eslint-comments/no-unused-disable': 'warn',
'eslint-comments/no-unlimited-disable': 'warn',
'eslint-comments/disable-enable-pair': 'warn',
// Heuristic to try to detect secrets accidentally left in the code
// 'no-secrets/no-secrets': 'warn',
// Unluckily this rule has a very high false-positivity rate, making it unusable
'security/detect-object-injection': 'off',
// Improve regexes by making them shorter, more consistent, and safer
// 'require-unicode-regexp': 'warn',
'unicorn/better-regex': 'warn',
'unicorn/no-unsafe-regex': 'warn',
// Best practices for Promises and async methods
'no-return-await': 'warn',
'prefer-promise-reject-errors': 'warn',
// Best practices for errors
'no-throw-literal': 'warn',
'unicorn/custom-error-definition': 'warn',
'unicorn/error-message': 'warn',
'unicorn/throw-new-error': 'warn',
// Best practices for Arrays
'array-callback-return': ['warn', {allowImplicit: true, checkForEach: true}],
'unicorn/no-array-push-push': 'warn',
'unicorn/prefer-array-find': 'warn',
'unicorn/prefer-array-flat-map': 'warn',
'unicorn/prefer-array-index-of': 'warn',
'unicorn/prefer-array-some': 'warn',
'unicorn/prefer-includes': 'warn',
'unicorn/no-instanceof-array': 'warn',
'unicorn/prefer-negative-index': 'warn',
'unicorn/no-array-callback-reference': 'warn',
// Best practices for Strings
'unicorn/prefer-regexp-test': 'warn',
'unicorn/prefer-string-replace-all': 'warn',
'unicorn/prefer-string-slice': 'warn',
'unicorn/prefer-string-starts-ends-with': 'warn',
'unicorn/prefer-string-trim-start-end': 'warn',
'unicorn/escape-case': 'warn',
// Best practices for Numbers
'unicorn/prefer-number-properties': 'warn',
'unicorn/numeric-separators-style': 'warn',
'unicorn/no-zero-fractions': 'warn',
'unicorn/number-literal-case': 'warn',
'unicorn/prefer-math-trunc': 'warn',
// Disallow nested ternary expressions, that are hard to read
// 'unicorn/no-nested-ternary': 'warn',
// Prefer Set#has() over Array#includes() when checking for existence or non-existence,
// as it's faster
'unicorn/prefer-set-has': 'warn',
// Avoid using sync versions of functions, that would block the event loop on the server,
// potentially blocking all requests
'node/no-sync': 'warn',
// Don't use console.log, prefer the Nest logger instead
'no-console': 'warn',
// Add one space before comment texts
'spaced-comment': [
'warn',
'always',
{
line: {
markers: ['/'],
},
block: {
markers: ['!'],
balanced: true,
},
},
],
},
overrides: [
// Rules specific to files that should be treated as modules
{
files: ['*.ts', '*.tsx', '*.mjs'],
extends: ['plugin:node/recommended-module'],
rules: {
// Use only imports/exports, no commonjs in modules
'import/no-commonjs': 'warn',
// Always use named exports, as they work better with refactoring tools and IDEs
'import/no-default-export': 'warn',
// Already handled by eslint-plugin-import
'node/no-missing-import': 'off',
},
},
// Rules specific to files that should be treated as commonjs
{
files: ['*.js', '*.cjs'],
extends: ['plugin:node/recommended-script'],
},
// Rules specific to TypeScript files
{
files: ['*.ts', '*.tsx'],
parserOptions: {
projectService: true,
tsconfigRootDir: __dirname,
},
extends: [
'plugin:import/typescript',
// TODO: allow for stricter rules
// 'plugin:@typescript-eslint/recommended-type-checked'
// TODO: consider moving this further to strict
// 'plugin:@typescript-eslint/strict-type-checked'
],
rules: {
// Unsupported syntax will be transpiled by TypeScript anyway
'node/no-unsupported-features/es-syntax': 'off',
// Use explicit type signatures for everything that is exported from a module
// This works as a live documentation system and helps catching more errors.
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
// Disable const x = require("module") syntax (use imports instead)
'@typescript-eslint/no-var-requires': 'warn',
},
},
// Rules specific to test files
{
files: ['*.spec.*', '*.e2e-spec.*'],
env: {
'jest/globals': true,
},
extends: ['plugin:jest/recommended', 'plugin:jest/style'],
rules: {
// In test files we can load modules that are not part of the production dependencies
'node/no-unpublished-import': 'off',
// Make sure that tests contain at least one assertion.
// Recognizes as assertion Jest's built-in "expect" and SuperTest's request().expect()
'jest/expect-expect': [
'warn',
{
assertFunctionNames: ['expect', 'request.*.expect'],
},
],
},
},
// Rules specific to config files
{
files: ['*.config.js'],
rules: {
// Configuration files are kebab-cased and have the ".config" suffix
'filenames/match-regex': ['warn', `^[a-z]+(-[a-z0-9]+)*\\.config$`],
// In configuration files we can use dev dependencies
'node/no-unpublished-require': 'off',
},
},
// Rules specific to .eslintrc.js file
{
files: ['.eslintrc.js'],
rules: {
'node/no-unpublished-require': 'off',
},
},
// Next.js needs default exports for pages and API points
{
files: ['src/pages/**/*'],
rules: {
'import/no-default-export': 'off',
},
},
// SCSS types use default exports
{
files: ['src/index.scss.d.ts', 'src/**/*.module.scss.d.ts'],
rules: {
'import/no-default-export': 'off',
},
},
// generated types contain many `any`s
{
files: ['src/types/api/generated/**/*.ts'],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
},
},
],
}