forked from trezor/trezor-suite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eslintrc.js
372 lines (369 loc) · 14.8 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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
const path = require('path');
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
// latest is best, because it's backwards compatible and we have linted everything
ecmaVersion: 'latest',
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
},
plugins: [
'import',
'@typescript-eslint',
'react-hooks',
'jest',
'chai-friendly',
'react',
'local-rules',
],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:react/recommended',
'plugin:import/typescript',
'plugin:react-hooks/recommended',
],
settings: {
react: {
version: 'detect',
},
'import/ignore': ['node_modules', '\\.(coffee|scss|css|less|hbs|svg|json)$'],
'import/resolver': {
node: {
paths: [path.resolve(__dirname, 'eslint-rules')],
},
},
},
env: {
jest: true,
'jest/globals': true,
},
ignorePatterns: [
'**/lib/*',
'**/libDev/*',
'**/dist/*',
'**/coverage/*',
'**/build/*',
'**/build-electron/*',
'**/node_modules/*',
'**/public/*',
'packages/suite-data/files/*',
'packages/protobuf/scripts/protobuf-patches/*',
'packages/address-validator',
'packages/connect-examples',
'ci/',
'eslint-local-rules/*',
],
rules: {
'@typescript-eslint/no-empty-object-type': 'off',
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/prefer-ts-expect-error': 'error',
// I believe type is enforced by callers.
'@typescript-eslint/explicit-function-return-type': 'off',
// Enforce arrow functions only is afaik not possible. But this helps.
'func-style': [
'error',
'declaration',
{
allowArrowFunctions: true,
},
],
// Fix for TypeScript.
'react/jsx-filename-extension': [
'error',
{
extensions: ['.tsx'],
},
],
'import/order': [
1,
{
groups: [['builtin', 'external'], 'internal', ['sibling', 'parent']],
pathGroups: [
{
pattern: 'react*',
group: 'external',
position: 'before',
},
{ pattern: '@trezor/**', group: 'internal' }, // Translates to /packages/** */
{ pattern: '@suite-native/**', group: 'internal' },
{ pattern: '@suite-common/**', group: 'internal' },
{ pattern: 'src/**', group: 'internal', position: 'after' },
],
pathGroupsExcludedImportTypes: ['internal', 'react'],
'newlines-between': 'always',
},
],
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: [
'**/*fixtures*/**',
'**/*.test.{tsx,ts,js}',
'**/blockchain-link/tests/**',
'**/blockchain-link/webpack/**',
'**/suite-desktop-core/**',
'**/*e2e/**',
'**/suite/src/support/tests/**',
'**/suite-data/**',
'**/*.stories.*',
'**/*webpack.config*',
'**/webpack/**',
],
includeTypes: true,
},
],
// This promotes using default case, which is not always correct (explicit is better than implicit)
'default-case': 'off',
// Does not work with TypeScript export type.
'import/prefer-default-export': 'off',
'import/no-named-as-default': 'off', // default export is forbidden anyway
'no-nested-ternary': 'error',
// Does not work with Babel react-native to react-native-web
'import/no-unresolved': 'off',
'import/extensions': 'off',
// Could be useful, but it's very very very slow
'import/no-cycle': 'off',
'import/no-anonymous-default-export': [
'error',
{
allowArray: true,
allowLiteral: true,
allowObject: true,
},
],
// We have typescript.
'react/prop-types': 'off',
// It's fine.
'react/no-multi-comp': 'off',
'react/no-unescaped-entities': 'off',
'react/jsx-curly-brace-presence': ['warn', { props: 'never', children: 'never' }],
// This is fine.
'class-methods-use-this': 'off',
'lines-between-class-members': 'off',
// We use it for immer. It should be checked by readonly anyway.
'no-param-reassign': 'off',
// Irrelevant.
'no-plusplus': 'off',
'no-return-assign': 'off',
'consistent-return': 'off',
'no-console': ['error', { allow: ['warn', 'error'] }],
// TSC checks it.
'no-undef': 'off',
'react/jsx-no-undef': 'off',
'react/react-in-jsx-scope': 'off',
// React Hooks.
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'error',
// Reconsider, maybe enable later:
'@typescript-eslint/explicit-member-accessibility': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'react/destructuring-assignment': 'off',
'func-names': 'off',
'react/require-default-props': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
// We use this syntax
'@typescript-eslint/triple-slash-reference': 'off',
// new rules (eslint 6) temporary disabled until components-v2 and ts-ignore resolve
'react/jsx-props-no-spreading': 'off',
'@typescript-eslint/ban-ts-ignore': 'off',
// We need empty functions for mocking modules for react-native
'@typescript-eslint/no-empty-function': 'off',
'no-useless-constructor': 'off',
'@typescript-eslint/no-useless-constructor': 'error',
// valid case of class method overloads in typescript
'no-dupe-class-members': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
// Missing return type on function
'@typescript-eslint/explicit-module-boundary-types': 'off',
// note you must disable the base rule as it can report incorrect errors
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': ['error'],
'require-await': ['error'],
'react/display-name': 'off',
'react/jsx-key': 'warn',
'react/prefer-stateless-function': 'off', // we don't use classes at all
'react/no-deprecated': 'off', // checked by TS
'react/no-direct-mutation-state': 'off', // we don't use classes at all
'react/require-render-return': 'off', // we don't use classes at all
'react/no-is-mounted': 'off', // we don't use classes at all
'react/jsx-indent': 'off', // we use prettier
'prefer-destructuring': [
'error',
{
VariableDeclarator: {
array: false,
object: true,
},
AssignmentExpression: {
array: false,
object: false,
},
},
{
enforceForRenamedProperties: false,
},
],
// Node.js
// These rules are specific to JavaScript running on Node.js.
'handle-callback-err': 'error', // enforces error handling in callbacks (off by default) (on by default in the node environment)
'no-mixed-requires': 'error', // disallow mixing regular variable and require declarations (off by default) (on by default in the node environment)
'no-new-require': 'error', // disallow use of new operator with the require function (off by default) (on by default in the node environment)
'no-path-concat': 'error', // disallow string concatenation with __dirname and __filename (off by default) (on by default in the node environment)
'no-process-exit': 'off', // disallow process.exit() (on by default in the node environment)
'no-restricted-modules': 'error', // restrict usage of specified node modules (off by default)
'no-sync': 'off', // disallow use of synchronous methods (off by default)
'eol-last': 'error',
'import/no-default-export': 'error',
// Variables
// These rules have to do with variable declarations.
'no-label-var': 'error', // disallow labels that share a name with a variable
'no-shadow': 'off', // @typescript-eslint/no-shadow will be used instead
'@typescript-eslint/no-shadow': [
'error',
{ builtinGlobals: true, allow: ['_', 'error', 'resolve', 'reject', 'fetch'] },
], // disallow declaration of variables already declared in the outer scope
'no-shadow-restricted-names': 'error', // disallow shadowing of names such as arguments
'no-undefined': 'off', // disallow use of undefined variable (off by default)
'no-undef-init': 'error', // disallow use of undefined when initializing variables
'no-unused-vars': 'off',
'no-unused-expressions': 0,
'prefer-const': 'off',
'chai-friendly/no-unused-expressions': 2,
'@typescript-eslint/no-unused-vars': [
'error',
{ vars: 'all', args: 'none', ignoreRestSiblings: true, varsIgnorePattern: '^_' },
],
'@typescript-eslint/no-restricted-imports': [
'error',
{
paths: [{ name: '.' }, { name: '..' }, { name: '../..' }],
patterns: ['@trezor/*/lib', '@trezor/*/lib/**'],
},
],
'no-restricted-syntax': [
'error',
{
message:
"Please don't use createAsyncThunk. Use createThunk from @suite-common/redux-utils instead.",
selector: "CallExpression[callee.name='createAsyncThunk']",
},
{
message:
'Please don\'t use getState directly. Always use strongly typed selector, because geState is typed as "any" and it\'s dangerous to use it directly.',
selector:
'MemberExpression[property.type="Identifier"]:matches([object.callee.name="getState"])',
},
{
message:
'Do not assign "getState" directly. Always use strongly typed selector, because geState is typed as "any" and it\'s dangerous to use it directly.',
selector:
"VariableDeclarator[init.type='CallExpression']:matches([init.callee.name='getState'])",
},
{
message:
'Please don\'t use "state" directly because it\'s typed as "any". Always use it only as parameter for strongly typed selector function.',
selector:
"CallExpression[callee.name='useSelector'] MemberExpression[object.name='state']:matches([property.type='Identifier'])",
},
],
'object-shorthand': [
'error',
'always',
{
ignoreConstructors: false,
avoidQuotes: true,
},
],
'constructor-super': 'error',
'no-duplicate-imports': 'off',
// disallow renaming import, export, and destructured assignments to the same name
// https://eslint.org/docs/rules/no-useless-rename
'no-useless-rename': [
'error',
{
ignoreDestructuring: false,
ignoreImport: false,
ignoreExport: false,
},
],
'prefer-numeric-literals': 'error',
'padding-line-between-statements': [
'error',
{ blankLine: 'always', prev: '*', next: 'return' },
],
'local-rules/no-override-ds-component': ['error', { packageName: '@trezor/components' }],
'local-rules/no-override-ds-component': [
'error',
{ packageName: '@trezor/product-components' },
],
},
overrides: [
{
files: ['**/*.js'],
rules: {
// JS files are usually configs or scripts where require is OK
'@typescript-eslint/no-var-requires': 'off',
'no-console': 'off',
},
},
{
// we are using explicit blacklist because this will enforce new rules in newly created packages
files: [
'packages/analytics/**/*',
'packages/blockchain-link/**/*',
'packages/components/**/*',
'packages/product-components/**/*',
'packages/connect/**/*',
'packages/connect-common/**/*',
'packages/connect-explorer/**/*',
'packages/connect-web/**/*',
'packages/connect-popup/**/*',
'packages/connect-iframe/**/*',
'packages/connect-examples/**/*',
'packages/connect-plugin-ethereum/**/*',
'packages/connect-plugin-stellar/**/*',
'packages/request-manager/**/*',
'packages/suite/**/*',
'packages/suite-build/**/*',
'packages/suite-data/**/*',
'packages/suite-desktop-api/**/*',
'packages/suite-storage/**/*',
'packages/suite-web/**/*',
'packages/transport/**/*',
'packages/utxo-lib/**/*',
'scripts/**/*',
'docs/**/*',
],
rules: {
'@typescript-eslint/no-shadow': 'off',
'import/no-default-export': 'off',
'import/order': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'no-console': 'off',
'react/jsx-no-undef': 'off',
'no-catch-shadow': 'off',
'@typescript-eslint/no-restricted-imports': 'off',
'no-restricted-syntax': 'off',
},
},
{
files: ['suite-native/**/*'],
rules: {
'@typescript-eslint/no-var-requires': 'off',
'global-require': 'off',
},
},
// tests
{
files: ['**/*.test.*', '**/__tests__/**/*'],
rules: {
'import/no-extraneous-dependencies': 'off',
'import/no-unresolved': 'off',
'import/no-default-export': 'off',
},
},
],
};