-
Notifications
You must be signed in to change notification settings - Fork 2
/
.eslintrc.js
181 lines (160 loc) · 6.07 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
module.exports = {
root: true,
reportUnusedDisableDirectives: true,
overrides: [],
parserOptions: {
parser: '@typescript-eslint/parser',
tsconfigRootDir: __dirname,
project: './tsconfig.json',
},
plugins: ['react-perf', 'relay', '@typescript-eslint', 'import'],
extends: [
'airbnb-typescript/base',
'airbnb/rules/react',
'airbnb/rules/react-a11y',
'plugin:relay/strict',
'next/core-web-vitals',
],
'ignorePatterns': ['temp.js', '**/route.ts'],
rules: {
'react/destructuring-assignment': 'off',
'react/jsx-filename-extension': ['error', { extensions: ['.jsx', '.tsx', '.mdx'] }],
// We utilize prop spreading
'react/jsx-props-no-spreading': 'off',
// We utilize class properties
'react/state-in-constructor': 'off',
// Dont use prop types since were using TypeScript
'react/default-props-match-prop-types': 'off',
'react/forbid-foreign-prop-types': 'off',
'react/forbid-prop-types': 'off',
'react/no-unused-prop-types': 'off',
'react/prefer-read-only-props': 'off',
'react/prop-types': 'off',
'react/require-default-props': 'off',
'react/sort-prop-types': 'off',
// Performance: Avoid unnecessary renders
'react-perf/jsx-no-new-array-as-prop': 'warn',
'react-perf/jsx-no-new-function-as-prop': 'warn',
// We prefer function declarations
'react/function-component-definition': [
'error',
{ namedComponents: 'function-declaration', unnamedComponents: 'function-expression' },
],
// We prefer on/handle named events
'react/jsx-handler-names': 'error',
// We require named functions for inferred `displayName`
// This is required for memo() and forwardRef() usage
'prefer-arrow-callback': ['error', { allowNamedFunctions: true }],
'react/jsx-one-expression-per-line': 'off',
// We dont use flow
'relay/generated-flow-types': 'off',
// Shorthand types
'@typescript-eslint/array-type': ['error', { default: 'array' }],
'@typescript-eslint/consistent-indexed-object-style': ['error', 'record'],
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
'@typescript-eslint/method-signature-style': ['error', 'property'],
'@typescript-eslint/no-inferrable-types': 'error',
// Forbid types
'@typescript-eslint/ban-types': 'error',
'@typescript-eslint/no-explicit-any': ['error', { fixToUnknown: true }],
'@typescript-eslint/no-invalid-void-type': 'error',
'@typescript-eslint/no-unsafe-argument': 'error',
'@typescript-eslint/no-unsafe-assignment': 'error',
'@typescript-eslint/no-unsafe-call': 'error',
'@typescript-eslint/no-unsafe-return': 'error',
// Readability
'@typescript-eslint/adjacent-overload-signatures': 'error',
'@typescript-eslint/no-empty-interface': ['error', { allowSingleExtends: false }],
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 'error',
'@typescript-eslint/semi': ['error', 'never'],
'@typescript-eslint/indent': 'off',
// Correctness
'@typescript-eslint/switch-exhaustiveness-check': 'error',
'@typescript-eslint/no-for-in-array': 'error',
'@typescript-eslint/no-misused-new': 'error',
'@typescript-eslint/no-this-alias': 'error',
'@typescript-eslint/no-unnecessary-qualifier': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/no-unnecessary-type-constraint': 'error',
'@typescript-eslint/prefer-for-of': 'error',
'@typescript-eslint/prefer-literal-enum-member': 'error',
'@typescript-eslint/restrict-plus-operands': 'error',
'@typescript-eslint/unified-signatures': 'error',
// Assertions
'@typescript-eslint/consistent-type-assertions': 'error',
'@typescript-eslint/no-confusing-non-null-assertion': 'error',
'@typescript-eslint/no-extra-non-null-assertion': 'error',
'@typescript-eslint/no-non-null-assertion': 'error',
'@typescript-eslint/no-non-null-asserted-optional-chain': 'error',
'@typescript-eslint/prefer-as-const': 'error',
// Comments
'@typescript-eslint/ban-ts-comment': ['error', { 'ts-expect-error': 'allow-with-description' }],
'@typescript-eslint/prefer-ts-expect-error': 'error',
'@typescript-eslint/triple-slash-reference': [
'error',
{ path: 'never', types: 'never', lib: 'never' },
],
// Async
'no-void': 'off',
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-misused-promises': 'error',
'@typescript-eslint/promise-function-async': 'error',
// APIs
'@typescript-eslint/prefer-includes': 'error',
'@typescript-eslint/prefer-nullish-coalescing': 'error',
'@typescript-eslint/prefer-optional-chain': 'error',
'@typescript-eslint/prefer-string-starts-ends-with': 'error',
// Hard to migrate
// Errors for all try/catch blocks and any types from third-parties
'@typescript-eslint/no-unsafe-member-access': 'off',
// We prefer React named imports only
'react/jsx-uses-react': 'off',
'react/react-in-jsx-scope': 'off',
'import/extensions': 'off',
// We prefer sorting imports by groups
'import/order': [
'error',
{
'alphabetize': {
'order': 'asc',
'caseInsensitive': true,
},
'groups': [
'builtin',
'external',
'internal',
'parent',
'sibling',
'index',
'object',
'type',
],
'pathGroups': [
{
'pattern': 'react',
'group': 'external',
'position': 'before',
},
{
'pattern': '@/**',
'group': 'external',
'position': 'after',
},
],
'pathGroupsExcludedImportTypes': ['react'],
},
],
// We prefer labels to be associated with inputs
'jsx-a11y/label-has-associated-control': ['error', {
'required': {
'some': ['nesting', 'id'],
},
}],
'jsx-a11y/label-has-for': ['error', {
'required': {
'some': ['nesting', 'id'],
},
}],
},
}