forked from remirror/remirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eslintrc.js
199 lines (185 loc) · 6.13 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
const { EXCLUDE_TS } = process.env;
const tsProjectOptions = EXCLUDE_TS ? {} : { project: ['./tsconfig.lint.json'] };
const tsProjectRules = EXCLUDE_TS
? {}
: {
'@typescript-eslint/prefer-readonly': 'warn',
'@typescript-eslint/await-thenable': 'warn',
'@typescript-eslint/no-unnecessary-type-assertion': 'warn',
'@typescript-eslint/no-unnecessary-type-arguments': 'warn',
'@typescript-eslint/restrict-plus-operands': 'warn',
'@typescript-eslint/no-misused-promises': 'warn',
'@typescript-eslint/no-unnecessary-condition': ['warn', { ignoreRhs: true }],
'@typescript-eslint/prefer-includes': 'warn',
'@typescript-eslint/prefer-string-starts-ends-with': 'warn',
};
module.exports = {
parser: '@typescript-eslint/parser',
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended', // Disables incompatible eslint:recommended settings
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
// 'plugin:jsx-a11y/recommended',
'plugin:react/recommended',
'plugin:import/typescript',
'prettier',
'prettier/@typescript-eslint',
'prettier/react',
],
plugins: [
'jest',
'@typescript-eslint',
'react-hooks',
'react',
'prettier',
'unicorn',
'import',
'jsx-a11y',
],
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
...tsProjectOptions,
},
settings: {
react: {
version: 'detect',
},
},
env: {
browser: true,
node: true,
jest: true,
es6: true,
},
rules: {
eqeqeq: ['warn', 'always', { null: 'ignore' }],
'unicorn/filename-case': ['error', { case: 'kebabCase' }],
'default-case': 'warn',
'@typescript-eslint/array-type': [
'error',
{ default: 'array-simple', readonly: 'array-simple' },
],
'prefer-template': 'warn',
'guard-for-in': 'warn',
'@typescript-eslint/camelcase': [
'warn',
{ ignoreDestructuring: true, properties: 'never' },
],
'@typescript-eslint/no-empty-function': 'off', // Empty functions/methods are often desired
'@typescript-eslint/no-empty-interface': 'off', // Empty interfaces are useful for future planning
'@typescript-eslint/no-var-requires': 'off', // We use 'require(..)' throughout
'jest/no-focused-tests': 'error',
'jest/no-identical-title': 'error',
'jest/no-duplicate-hooks': 'warn',
'jest/no-if': 'warn',
'jest/no-test-prefixes': 'warn',
'jest/prefer-spy-on': 'warn',
'jest/no-test-callback': 'warn',
'jest/no-large-snapshots': ['warn', { maxSize: 12 }],
'react/prop-types': 'off', // Because we're using TypeScript
'react-hooks/exhaustive-deps': 'error',
'react-hooks/rules-of-hooks': 'error',
'import/no-deprecated': 'warn',
'import/first': 'warn',
'import/no-duplicates': 'error',
'import/no-cycle': 'error',
'import/no-self-import': 'error',
'import/newline-after-import': 'warn',
// ESLint rules (those without a '/' in) come after here
'no-nested-ternary': 'off', // Prettier makes nested ternaries more acceptable
'no-return-assign': ['error', 'except-parens'],
'no-unused-expressions': ['error', { allowTernary: true }],
'prefer-arrow-callback': ['error', { allowNamedFunctions: true }],
// Temporarily disabled rules (please re-enable these!):
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/no-namespace': 'off', // Migrate all the global namespaces to be in .d.ts files (see overrides)
'@typescript-eslint/no-non-null-assertion': 'warn',
'@typescript-eslint/no-use-before-define': 'warn',
'@typescript-eslint/no-unused-vars': [
'warn',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
args: 'after-used',
ignoreRestSiblings: true,
},
],
'@typescript-eslint/ban-types': 'warn',
'react/display-name': 'warn',
'react/no-unescaped-entities': 'warn',
'react/no-unused-state': 'warn',
'react/no-children-prop': 'warn',
'react/no-multi-comp': 'off', // Might want to enable this later
'no-invalid-regexp': 'warn',
'no-multi-str': 'warn',
'no-constant-condition': 'warn',
'no-extra-boolean-cast': 'warn',
'no-empty': 'warn', // Later, put a `/* noop */` comment in empty blocks to explain why
'no-useless-escape': 'warn',
radix: 'warn',
'prefer-object-spread': 'warn',
curly: ['warn', 'all'],
},
overrides: [
{
files: ['*.ts', '*.tsx'],
rules: {
...tsProjectRules,
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
'@typescript-eslint/explicit-member-accessibility': [
'warn',
{
accessibility: 'explicit',
overrides: {
accessors: 'off',
constructors: 'no-public',
methods: 'explicit',
properties: 'explicit',
parameterProperties: 'explicit',
},
},
],
'@typescript-eslint/no-var-requires': 'error',
'@typescript-eslint/camelcase': [
'warn',
{ ignoreDestructuring: true, properties: 'never' },
],
},
},
{
files: ['**/__tests__/**'],
rules: {
'@typescript-eslint/ban-ts-ignore': 'off', // Often you need to use @ts-ignore in tests
'@typescript-eslint/no-non-null-assertion': 'off', // Makes writing tests more convenient
'@typescript-eslint/no-use-before-define': 'off',
'react/display-name': 'off',
...Object.keys(tsProjectRules).reduce(
(acc, key) => ({ ...acc, [key]: 'off' }),
{},
),
},
},
{
files: ['**/*.d.ts'],
rules: {
'import/no-duplicates': 'off',
'@typescript-eslint/no-namespace': 'off',
},
},
{
files: ['**/*.dts.ts'],
rules: {
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'no-unused-expressions': 'off',
},
},
],
};