-
Notifications
You must be signed in to change notification settings - Fork 10
/
.eslintrc.js
222 lines (211 loc) · 6.62 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
// eslint-disable-next-line import/no-commonjs
module.exports = {
extends: [
"@khanacademy",
// This config includes rules from @testing-library/jest-dom as well
"plugin:testing-library/react",
// This config includes rules from storybook to enforce story best
// practices
"plugin:storybook/recommended",
],
plugins: [
"import",
"jest",
"jsdoc",
"promise",
"monorepo",
"react-hooks",
"@babel",
],
settings: {
"import/resolver": {
typescript: {
project: [
"packages/*/tsconfig.json",
"packages/tsconfig-shared.json",
],
extensions: [".js", ".jsx", ".ts", ".tsx"],
moduleDirectory: ["node_modules"],
},
node: {
project: [
"packages/*/tsconfig.json",
"packages/tsconfig-shared.json",
],
extensions: [".js", ".jsx", ".ts", ".tsx"],
moduleDirectory: ["node_modules"],
},
},
react: {
version: "detect",
},
},
overrides: [
{
files: ["build-settings/*.ts"],
rules: {
"no-console": "off",
},
},
{
files: ["utils/*.js"],
rules: {
"import/no-commonjs": "off",
},
},
{
files: ["**/*.test.ts", "**/*.test.tsx"],
rules: {
"no-undef": "off",
},
},
{
files: ["**/*.stories.tsx"],
rules: {
"testing-library/no-await-sync-events": "off",
},
},
],
globals: {
// `no-undef` doesn't support `globalThis`, for details see
// https://github.com/eslint/eslint/issues/15199.
globalThis: false, // means it isn't writeable
// from node_modules/@types/react/index.d.ts
JSX: false,
// from node_modules/typescript/lib/lib.dom.d.ts
DOMHighResTimeStamp: false,
RequestInfo: false,
RequestInit: false,
// from types/assets.d.ts
PhosphorBold: false,
PhosphorFill: false,
PhosphorRegular: false,
// from types/utility.d.ts
Empty: false,
ObjMap: false,
SpreadType: false,
},
rules: {
"no-restricted-syntax": [
"error",
{
selector: "TSQualifiedName[left.name='React'][right.name='FC']",
message:
"Use of React.FC<Props> is disallowed, use the following alternative: https://khanacademy.atlassian.net/wiki/spaces/ENG/pages/2201682693/TypeScript+for+Flow+Developers#Functional-Components",
},
],
/**
* import rules
*/
"import/named": "off", // NOTE(kevinb): This rule is confused by third-party TypeScript lib defs
"import/no-unresolved": "error",
"import/default": "error",
"import/no-absolute-path": "error",
"import/no-self-import": "error",
"import/no-useless-path-segments": "error",
"import/no-named-as-default": "error",
"import/no-named-as-default-member": "error",
"import/no-deprecated": "error",
"import/no-commonjs": "error",
"import/first": "error",
"import/no-duplicates": "error",
"import/order": [
"error",
{
groups: ["builtin", "external"],
},
],
"import/newline-after-import": "error",
"import/no-unassigned-import": "error",
"import/no-named-default": "error",
"import/extensions": [
"error",
"never",
{
ignorePackages: true,
pattern: {
json: "always",
},
},
],
// NOTE: This rule reports false positives for cross-module imports using
// `@khanacademy/wonder-stuff-*`. This is likely due to a bad interaction
// with the settings we're using for `import/resolver`.
// "monorepo/no-relative-import": "error",
"import/no-restricted-paths": [
"error",
{
zones: [
{
target: "./packages/(?!.*test.js).*",
from: "utils",
},
{
target: "./packages/wonder-blocks.*",
from: "./shared-unpackaged",
},
],
},
],
/**
* jest rules
*/
"jest/no-focused-tests": "error",
/**
* jsdoc rules
*/
"jsdoc/valid-types": "error",
/**
* monorepo rules
*/
"monorepo/no-internal-import": "error",
/**
* promise rules
*/
"promise/always-return": "error",
"promise/no-return-wrap": "error",
"promise/param-names": "error",
"promise/catch-or-return": "error",
"promise/no-new-statics": "error",
"promise/no-return-in-finally": "error",
/**
* react rules
*/
"react/jsx-handler-names": "error",
"react/no-children-prop": "error",
"react/no-direct-mutation-state": "error",
"react/no-typos": "error",
"react/no-string-refs": "error",
"react/no-this-in-sfc": "error",
"react/no-unescaped-entities": "error",
"react/no-deprecated": "error",
"react/react-in-jsx-scope": "error",
"react/require-render-return": "error",
/**
* react-hooks rules
*/
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "error",
/**
* testing-library rules
*/
"testing-library/prefer-user-event": "error",
// These rules results in a lot of false positives
"testing-library/render-result-naming-convention": "off",
"testing-library/await-async-utils": "off",
"testing-library/await-async-query": "off",
// @khanacademy
"@khanacademy/jest-await-async-matchers": [
"error",
{
matchers: ["toHaveNoA11yViolations"],
},
],
/**
* TypeScript rules
*/
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/prefer-enum-initializers": "error",
"@typescript-eslint/prefer-literal-enum-member": "error",
},
};