-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.eslintrc.js
146 lines (143 loc) · 4.55 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
const baseline = require('@mui/monorepo/.eslintrc');
const lodash = require('lodash');
const ALLOWED_LODASH_METHODS = new Set(['throttle', 'debounce', 'set']);
module.exports = {
...baseline,
extends: [
...baseline.extends,
// Motivation: https://github.com/shian15810/eslint-plugin-typescript-enum#motivations
'plugin:typescript-enum/recommended',
],
/**
* Sorted alphanumerically within each group. built-in and each plugin form
* their own groups.
*/
rules: {
...baseline.rules,
'import/prefer-default-export': ['off'],
// TODO move rule into the main repo once it has upgraded
'@typescript-eslint/return-await': ['off'],
'no-restricted-imports': [
'error',
{
paths: [
{
name: '@mui/icons-material',
message: 'Use @mui/icons-material/<Icon> instead.',
},
{
name: 'lodash-es',
importNames: Object.keys(lodash).filter((key) => !ALLOWED_LODASH_METHODS.has(key)),
message:
'Avoid kitchensink libraries like lodash-es. We prefer a slightly more verbose, but more universally understood javascript style',
},
],
patterns: [
{
group: ['lodash-es/*'],
message: 'Use `import { debounce } from "lodash-es";` instead.',
},
],
},
],
'no-restricted-syntax': [
...baseline.rules['no-restricted-syntax'].filter((rule) => {
// Too opinionated for Toolpad
return rule?.selector !== 'ForOfStatement';
}),
],
// Turning react/jsx-key back on.
// https://github.com/airbnb/javascript/blob/5155aa5fc1ea9bb2c6493a06ddbd5c7a05414c86/packages/eslint-config-airbnb/rules/react.js#L94
'react/jsx-key': ['error', { checkKeyMustBeforeSpread: true, warnOnDuplicates: true }],
// This got turned of in the mono-repo:
// See https://github.com/mui/mui-toolpad/pull/866#discussion_r957222171
'react/no-unused-prop-types': [
'error',
{
customValidators: [],
skipShapeProps: true,
},
],
'import/no-restricted-paths': [
// Disabling this rule for now, still need a few more refactors for it to pass
'off',
{
zones: [
{
target: './packages/toolpad-app/src/runtime',
from: './packages/toolpad-app/src/',
except: ['./runtime', './appDom', './types.ts'],
},
],
},
],
},
overrides: [
{
files: [
'packages/create-toolpad-app/**/*',
'packages/toolpad/**/*',
'packages/toolpad-app/**/*',
'packages/toolpad-utils/**/*',
'packages/toolpad-core/**/*',
'packages/toolpad-components/**/*',
],
excludedFiles: [
'**/jest-environment-jsdom.ts',
'tsup.config.ts',
'*.spec.ts',
'*.spec.tsx',
'jest.config.ts',
],
rules: {
'import/no-extraneous-dependencies': ['error'],
},
},
{
files: [
/**
* Basically all code that is guaranteed being bundled for the client side and never used on serverside code
* can be dev dependencies to reduce the size of the published package
*/
'packages/toolpad-app/src/components/**/*',
'packages/toolpad-app/src/toolpad/**/*',
'packages/toolpad-app/src/runtime/**/*',
'packages/toolpad-app/reactDevtools/**/*',
],
excludedFiles: ['*.spec.ts', '*.spec.tsx'],
rules: {
'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
},
},
{
// Starting small, we will progressively expand this to more packages.
files: [
// 'packages/create-toolpad-app/**/*',
// 'packages/toolpad/**/*',
// 'packages/toolpad-app/**/*',
'packages/toolpad-utils/**/*',
// 'packages/toolpad-core/**/*',
// 'packages/toolpad-components/**/*',
],
rules: {
'@typescript-eslint/no-explicit-any': ['error'],
},
},
{
files: ['packages/toolpad-app/pages/**/*'],
rules: {
// The pattern is useful to type Next.js pages
'react/function-component-definition': 'off',
},
},
{
// Disabling this rule for now:
// https://github.com/mui/material-ui/blob/9737bc85bb6960adb742e7709e9c3710c4b6cedd/.eslintrc.js#L359
files: ['packages/*/src/**/*{.ts,.tsx,.js}'],
excludedFiles: ['*.d.ts', '*.spec.ts', '*.spec.tsx'],
rules: {
'import/no-cycle': ['error', { ignoreExternal: true }],
},
},
],
};