forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.mjs
More file actions
298 lines (292 loc) · 8.59 KB
/
eslint.config.mjs
File metadata and controls
298 lines (292 loc) · 8.59 KB
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
import {
createBaseConfig,
createTestConfig,
baseSpecRules,
createDocsConfig,
EXTENSION_TS,
EXTENSION_TEST_FILE,
} from '@mui/internal-code-infra/eslint';
import { defineConfig } from 'eslint/config';
import eslintPluginConsistentName from 'eslint-plugin-consistent-default-export-name';
import eslintPluginReact from 'eslint-plugin-react';
import * as path from 'node:path';
import { fileURLToPath } from 'url';
const filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(filename);
const OneLevelImportMessage = [
'Prefer one level nested imports to avoid bundling everything in dev mode or breaking CJS/ESM split.',
'See https://github.com/mui/material-ui/pull/24147 for the kind of win it can unlock.',
].join('\n');
// This only applies to packages published from this monorepo.
// If you build a library around `@mui/material` you can safely use `createStyles` without running into the same issue as we are.
const forbidCreateStylesMessage =
'Use `MuiStyles<ClassKey, Props>` instead if the styles are exported. Otherwise use `as const` assertions. ' +
'`createStyles` will lead to inlined, at-compile-time-resolved type-imports. ' +
'See https://github.com/microsoft/TypeScript/issues/36097#issuecomment-578324386 for more information';
const ENABLE_REACT_COMPILER_PLUGIN = false;
const NO_RESTRICTED_IMPORTS_PATHS_TOP_LEVEL_PACKAGES = [
{
name: '@mui/material',
message: OneLevelImportMessage,
},
{
name: '@mui/lab',
message: OneLevelImportMessage,
},
];
const NO_RESTRICTED_IMPORTS_PATTERNS_DEEPLY_NESTED = [
{
group: [
'@mui/*/*/*',
'@pigment-css/*/*/*',
// Allow any import depth with any internal packages
'!@mui/internal-*/**',
'!@mui/docs/**', // @mui/docs should be @mui/internal-docs
],
message: OneLevelImportMessage,
},
];
export default defineConfig(
{
name: 'Base ESLint Configuration',
extends: createBaseConfig({
enableReactCompiler: ENABLE_REACT_COMPILER_PLUGIN,
baseDirectory: dirname,
}),
rules: {
'import/prefer-default-export': 'error',
'material-ui/straight-quotes': 'error',
'no-restricted-imports': [
'error',
{
patterns: NO_RESTRICTED_IMPORTS_PATTERNS_DEEPLY_NESTED,
},
],
'react/sort-prop-types': 'off', // 228
'@typescript-eslint/ban-ts-comment': 'off', // 117
'@typescript-eslint/no-require-imports': 'off', // 133
},
},
...['mui-material', 'mui-system', 'mui-utils', 'mui-lab', 'mui-utils', 'mui-styled-engine'].map(
(packageName) => ({
files: [`packages/${packageName}/src/**/*${EXTENSION_TEST_FILE}`],
ignores: ['**/*.test.*', '**/*.spec.*'],
rules: {
'material-ui/no-restricted-resolved-imports': [
'error',
[
{
pattern: `**/packages/${packageName}/src/index.*`,
message:
"Don't import from the package index. Import the specific module directly instead.",
},
],
],
},
}),
),
// Test start
{
files: [`**/*${EXTENSION_TEST_FILE}`, 'packages/mui-codemod/testUtils/**/*'],
extends: createTestConfig({
useMocha: true,
}),
rules: {
// Disabled temporarily. Enable one by one.
'testing-library/prefer-screen-queries': 'off',
'testing-library/no-container': 'off',
'testing-library/no-dom-import': 'off',
'testing-library/no-node-access': 'off',
'testing-library/render-result-naming-convention': 'off',
'testing-library/no-await-sync-queries': 'off',
'testing-library/no-unnecessary-act': 'off',
'testing-library/no-wait-for-multiple-assertions': 'off',
'testing-library/no-render-in-lifecycle': 'off',
},
},
// Test end
// Docs start
{
files: ['docs/**/*'],
extends: createDocsConfig(),
rules: {
'@next/next/no-img-element': 'off',
'no-restricted-imports': [
'error',
{
paths: NO_RESTRICTED_IMPORTS_PATHS_TOP_LEVEL_PACKAGES,
patterns: NO_RESTRICTED_IMPORTS_PATTERNS_DEEPLY_NESTED,
},
],
},
},
// Moved from docs/data/material/components/.eslintrc.js
{
files: ['docs/data/material/components/**/*'],
rules: {
// useful for interactions feedback
'no-console': ['off', { allow: ['info'] }],
// not very friendly to prop forwarding
'react/jsx-handler-names': 'off',
},
},
// demos
{
files: ['docs/src/pages/**/*', 'docs/data/**/*'],
rules: {
// This most often reports data that is defined after the component definition.
// This is safe to do and helps readability of the demo code since the data is mostly irrelevant.
'@typescript-eslint/no-use-before-define': 'off',
'react/prop-types': 'off',
'no-alert': 'off',
'no-console': 'off',
},
},
// Next.js entry points pages
{
files: ['docs/pages/**/*', 'packages/*/src/**/*.tsx'],
ignores: ['**/*.spec.tsx'],
rules: {
'react/prop-types': 'off',
},
},
{
files: ['docs/data/**/*'],
ignores: [
// filenames/match-exported sees filename as 'file-name.d'
// Plugin looks unmaintain, find alternative? (e.g. eslint-plugin-project-structure)
'**/*.d.ts',
'docs/data/joy/getting-started/templates/**/*',
'docs/data/**/{css,system,tailwind}/*',
],
plugins: {
'consistent-default-export-name': eslintPluginConsistentName,
},
rules: {
'consistent-default-export-name/default-export-match-filename': ['error'],
},
},
// Docs end
{
files: ['**/*.d.ts'],
rules: {
'import/export': 'off', // Not sure why it doesn't work
},
},
{
files: [`packages/*/src/*/*${EXTENSION_TS}`],
ignores: [
'**/*.spec.*',
'**/*.test.*',
// deprecated library
'**/mui-joy/**/*',
// used internally, not used on app router yet
'**/mui-docs/**/*',
],
rules: {
'material-ui/disallow-react-api-in-server-components': 'error',
},
},
{
files: [`packages/*/src/**/*${EXTENSION_TS}`],
ignores: ['**/*.spec.*'],
rules: {
'no-restricted-imports': [
'error',
{
paths: [
...NO_RESTRICTED_IMPORTS_PATHS_TOP_LEVEL_PACKAGES,
{
name: '@mui/utils',
message: OneLevelImportMessage,
},
{
name: '@mui/material/styles',
importNames: ['createStyles'],
message: forbidCreateStylesMessage,
},
],
},
],
},
},
baseSpecRules,
{
files: ['packages-internal/scripts/typescript-to-proptypes/src/**/*.ts'],
rules: {
// Working with flags is common in TypeScript compiler
'no-bitwise': 'off',
},
},
{
files: [`packages/*/src/**/*${EXTENSION_TS}`],
ignores: ['**/*.d.ts', '**/*.spec.*', 'packages/mui-joy/**/*'],
rules: {
'material-ui/mui-name-matches-component-name': 'error',
},
},
{
files: ['test/bundling/scripts/**/*.js'],
rules: {
// ES modules need extensions
'import/extensions': ['error', 'ignorePackages'],
},
},
// Migrated config from packages/mui-icons-material/.eslintrc.js
{
files: ['packages/mui-icons-material/custom/**/*'],
rules: {
'import/no-unresolved': 'off',
'import/extensions': 'off',
},
},
// Migrated config from packages/api-docs-builder/.eslintrc.js
{
files: ['packages/api-docs-builder/**/*'],
rules: {
'import/prefer-default-export': 'off',
},
},
// Migrated config from packages/api-docs-builder-core/.eslintrc.js
{
files: ['packages/api-docs-builder-core/**/*'],
rules: {
'import/no-default-export': 'error',
'import/prefer-default-export': 'off',
},
},
// Migrated config from apps/bare-next-app/.eslintrc.js
{
files: ['apps/**/*', 'examples/**/*'],
rules: {
'import/no-relative-packages': 'off',
'react/react-in-jsx-scope': 'off',
'react/prop-types': 'off',
},
},
{
files: ['examples/**/*'],
rules: {
'import/extensions': 'off',
'import/no-unresolved': 'off',
'no-console': 'off',
},
},
{
files: ['apps/pigment-css-vite-app/**/*'],
rules: {
'react/jsx-filename-extension': 'off',
'import/prefer-default-export': 'off',
},
},
{
files: ['apps/bare-next-app/**/*'],
extends: [eslintPluginReact.configs.flat['jsx-runtime']],
rules: {
'import/prefer-default-export': 'off',
'import/extensions': 'off',
'import/no-unresolved': 'off',
'react/no-unknown-property': ['error', { ignore: ['sx'] }],
},
},
);