forked from PostHog/posthog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eslintrc.js
369 lines (366 loc) · 12.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
/* global module */
const env = {
browser: true,
es6: true,
'cypress/globals': true,
}
const globals = {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
}
module.exports = {
ignorePatterns: ['node_modules', 'plugin-server'],
env,
settings: {
react: {
version: 'detect',
},
'import/resolver': {
node: {
paths: ['eslint-rules'], // Add the directory containing your custom rules
extensions: ['.js', '.jsx', '.ts', '.tsx'], // Ensure ESLint resolves both JS and TS files
},
},
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:react/recommended',
'plugin:eslint-comments/recommended',
'plugin:storybook/recommended',
'plugin:compat/recommended',
'prettier',
],
globals,
parser: '@typescript-eslint/parser',
parserOptions: {
project: true,
tsconfigRootDir: __dirname,
},
plugins: [
'react',
'cypress',
'@typescript-eslint',
'compat',
'posthog',
'simple-import-sort',
'import',
'unused-imports',
],
rules: {
// PyCharm always adds curly braces, I guess vscode doesn't, PR reviewers often complain they are present on props that don't need them
// let's save the humans time and let the machines do the work
// "never" means if the prop does not need the curly braces, they will be removed/errored
// see https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-curly-brace-presence.md
'react/jsx-curly-brace-presence': ['error', { props: 'never', children: 'never', propElementValues: 'always' }],
'no-console': ['error', { allow: ['warn', 'error'] }],
'no-debugger': 'error',
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
'react/prop-types': [0],
'react/react-in-jsx-scope': [0],
'react/no-unescaped-entities': [0],
'react/jsx-no-target-blank': [0],
'react/self-closing-comp': [
'error',
{
component: true,
html: true,
},
],
'unused-imports/no-unused-imports': 'error',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{
ignoreRestSiblings: true,
destructuredArrayIgnorePattern: '^_$',
},
],
'@typescript-eslint/prefer-ts-expect-error': 'error',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/require-await': 'off', // TODO: Enable - this rule is useful, but doesn't have an autofix
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-enum-comparison': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/explicit-function-return-type': [
'error',
{
allowExpressions: true,
},
],
'@typescript-eslint/explicit-module-boundary-types': [
'error',
{
allowArgumentsExplicitlyTypedAsAny: true,
},
],
curly: 'error',
'no-restricted-imports': [
'error',
{
paths: [
{
name: 'dayjs',
message: 'Do not directly import dayjs. Only import the dayjs exported from lib/dayjs.',
}
],
},
],
'react/forbid-dom-props': [
'error',
{
forbid: [
{
propName: 'style',
message:
'style should be avoided in favor of utility CSS classes - see https://storybook.posthog.net/?path=/docs/lemon-ui-utilities--overview',
},
],
},
],
'posthog/warn-elements': [
'warn',
{
forbid: [
{
element: 'Button',
message: 'use <LemonButton> instead',
},
{
element: 'Input',
message: 'use <LemonInput> instead',
},
{
element: 'Modal',
message: 'use <LemonModal> or `<LemonDialog> instead',
},
{
element: 'Select',
message: 'use <LemonSelect> instead',
},
{
element: 'LemonButtonWithDropdown',
message: 'use <LemonMenu> with a <LemonButton> child instead',
},
{
element: 'Progress',
message: 'use <LemonProgress> instead',
},
],
},
],
'react/forbid-elements': [
'error',
{
forbid: [
{
element: 'Layout',
message: 'use utility classes instead',
},
{
element: 'Tabs',
message: 'use <LemonTabs> instead',
},
{
element: 'Space',
message: 'use flex or space utility classes instead',
},
{
element: 'Spin',
message: 'use Spinner instead',
},
{
element: 'Badge',
message: 'use LemonBadge instead',
},
{
element: 'InputNumber',
message: 'use LemonInput with type="number" instead',
},
{
element: 'Collapse',
message: 'use <LemonCollapse> instead',
},
{
element: 'Slider',
message: 'use <LemonSlider> instead',
},
{
element: 'Checkbox',
message: 'use <LemonCheckbox> instead',
},
{
element: 'MonacoEditor',
message: 'use <CodeEditor> instead',
},
{
element: 'Typography',
message: 'use utility classes instead',
},
{
element: 'Input.TextArea',
message: 'use <LemonTextArea> instead',
},
{
element: 'ReactMarkdown',
message: 'use <LemonMarkdown> instead',
},
{
element: 'a',
message: 'use <Link> instead',
},
{
element: 'Tag',
message: 'use <LemonTag> instead',
},
{
element: 'Alert',
message: 'use <LemonBanner> instead',
},
{
element: 'ReactJson',
message: 'use <JSONViewer> for dark mode support instead',
},
{
element: 'Radio',
message: 'use <LemonRadio> instead',
},
{
element: 'Skeleton',
message: 'use <LemonSkeleton> instead',
},
{
element: 'Divider',
message: 'use <LemonDivider> instead',
},
{
element: 'Popconfirm',
message: 'use <LemonDialog> instead',
},
],
},
],
'no-constant-binary-expression': 'error',
'no-constant-condition': 'off',
'no-prototype-builtins': 'off',
'no-irregular-whitespace': 'off',
'no-useless-rename': 'error',
'import/no-restricted-paths': [
'error',
{
zones: [
{
target: './frontend/**',
from: './ee/frontend/**',
message:
"EE licensed TypeScript should only be accessed via the posthogEE objects. Use `import posthogEE from '@posthog/ee/exports'`",
},
],
},
],
'no-else-return': 'warn',
},
overrides: [
{
files: ['**/test/**/*', '**/*.test.*'],
env: {
...env,
node: true,
'jest/globals': true,
},
"plugins": ["jest"],
"extends": ["plugin:jest/recommended"],
globals: {
...globals,
given: 'readonly',
},
rules: {
// The below complains needlessly about expect(api.createInvite).toHaveBeenCalledWith(...)
'@typescript-eslint/unbound-method': 'off',
// it doesn't know about expectLogic kea tests so isn't helpful
'jest/expect-expect': 'off',
// we import non-jest mocks from __mocks__ directories
'jest/no-mocks-import': 'off',
// I'll put expect whereever I want
'jest/no-standalone-expect': 'off',
// but it's helpful sometimes
'jest/no-export': 'off',
// also helpful sometimes, but not always
'jest/no-conditional-expect': 'warn',
},
},
{
files: ['**/*.cy.ts'],
env: {
...env,
node: true,
'jest/globals': true,
},
"plugins": ["jest"],
"extends": ["plugin:jest/recommended"],
globals: {
...globals,
given: 'readonly',
},
rules: {
// don't complain about unknown expect statements
'jest/valid-expect': 'off',
// don't warn about missing expect
'jest/expect-expect': 'off'
},
},
{
files: ['*Type.ts', '*Type.tsx'], // Kea typegen output
rules: {
'no-restricted-imports': 'off',
'@typescript-eslint/ban-types': 'off',
'simple-import-sort/imports': 'off',
'simple-import-sort/exports': 'off',
},
},
{
files: ['frontend/src/scenes/notebooks/Nodes/*'], // Notebooks code weirdly relies on its order of sorting
rules: {
'simple-import-sort/imports': 'off',
'simple-import-sort/exports': 'off',
},
},
{
files: ['*.js'],
rules: {
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
},
},
{
files: ['*.mjs'],
rules: {
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-misused-promises': 'off',
'no-console': 'off',
},
globals: { ...globals, process: 'readonly' },
},
{
files: 'eslint-rules/**/*',
rules: {
'@typescript-eslint/no-var-requires': 'off',
},
env: {
node: true,
},
},
],
reportUnusedDisableDirectives: true,
}