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
166import {
baseSpecRules,
createBaseConfig,
createDocsConfig,
createTestConfig,
EXTENSION_TEST_FILE,
EXTENSION_TS,
} from '@mui/internal-code-infra/eslint';
import { defineConfig, globalIgnores } from 'eslint/config';
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');
const NO_RESTRICTED_IMPORTS_PATTERNS_DEEPLY_NESTED = [
{
group: ['@base-ui/react/*/*'],
message: OneLevelImportMessage,
},
];
// Add relevant packages to the list below.
const NO_RESTRICTED_IMPORTS_PATHS_TOP_LEVEL_PACKAGES = [
// { name: string, message: string }
];
export default defineConfig(
globalIgnores(['./examples']),
createBaseConfig({
baseDirectory: dirname,
}),
{
name: 'Base UI overrides',
files: [`**/*${EXTENSION_TS}`],
settings: {
'import/resolver': {
typescript: {
project: ['tsconfig.json'],
},
},
},
/**
* Sorted alphanumerically within each group. built-in and each plugin form
* their own groups.
*/
rules: {
// @TODO: Remove this once we move away from namespaces
'@typescript-eslint/no-namespace': 'off',
'import/export': 'off', // FIXME: Maximum call stack exceeded
'no-restricted-imports': [
'error',
{
patterns: NO_RESTRICTED_IMPORTS_PATTERNS_DEEPLY_NESTED,
},
],
// We LOVE non-breaking spaces, and both straight and curly quotes here
'no-irregular-whitespace': ['warn', { skipJSXText: true, skipStrings: true }],
'react/react-in-jsx-scope': 'off',
'react/no-unescaped-entities': ['warn', { forbid: ['>', '}'] }],
'react/prop-types': 'off',
'react-hooks/exhaustive-deps': [
'error',
{
additionalHooks: 'useIsoLayoutEffect',
},
],
// This prevents us from creating components like `<h1 {...props} />`
'jsx-a11y/heading-has-content': 'off',
'jsx-a11y/anchor-has-content': 'off',
// This rule doesn't recognise <label> wrapped around custom controls
'jsx-a11y/label-has-associated-control': 'off',
// Turn off new eslint-plugin-react-hooks rules till we can fix all warnings
'react-hooks/globals': 'off',
'react-hooks/immutability': 'off',
'react-hooks/incompatible-library': 'off',
'react-hooks/refs': 'off',
},
},
{
files: [`packages/*/src/**/*${EXTENSION_TS}`],
ignores: [`**/*${EXTENSION_TEST_FILE}`, `test/**/*${EXTENSION_TS}`],
rules: {
'material-ui/add-undef-to-optional': 'error',
},
},
{
files: [
// matching the pattern of the test runner
`**/*${EXTENSION_TEST_FILE}`,
],
extends: createTestConfig({ useMocha: false }),
rules: {
'material-ui/add-undef-to-optional': 'off',
},
},
baseSpecRules,
{
name: 'MUI ESLint config for docs',
files: [`docs/**/*${EXTENSION_TS}`],
extends: createDocsConfig(),
rules: {
'@typescript-eslint/no-use-before-define': 'off',
'import/extensions': [
'error',
// Ignores extensions in package imports as well as local ts/tsx imports but .mjs is always required
'ignorePackages',
{
ts: 'never',
tsx: 'never',
mjs: 'always',
},
],
'no-restricted-imports': [
'error',
{
paths: NO_RESTRICTED_IMPORTS_PATHS_TOP_LEVEL_PACKAGES,
patterns: NO_RESTRICTED_IMPORTS_PATTERNS_DEEPLY_NESTED,
},
],
},
},
{
files: [`docs/src/app/(private)/experiments/**/*${EXTENSION_TS}`],
rules: {
'@typescript-eslint/no-use-before-define': 'off',
'no-alert': 'off',
'no-console': 'off',
'import/no-relative-packages': 'off',
},
},
{
files: [`docs/src/app/(docs)/react/utils/use-render/demos/**/*${EXTENSION_TS}`],
rules: {
'jsx-a11y/control-has-associated-label': 'off',
'react/button-has-type': 'off',
},
},
{
name: 'Disable image rule for demos',
files: [
`docs/src/app/(docs)/**/demos/**/*${EXTENSION_TS}`,
`docs/src/app/(private)/experiments/**/*${EXTENSION_TS}`,
],
ignores: ['docs/src/app/(private)/experiments/**/page.tsx'],
rules: {
'@next/next/no-img-element': 'off',
},
},
{
files: [`test/**/*${EXTENSION_TS}`],
rules: {
'guard-for-in': 'off',
'testing-library/prefer-screen-queries': 'off', // Enable usage of playwright queries
'testing-library/no-await-sync-queries': 'off',
'testing-library/render-result-naming-convention': 'off', // inconsequential in regression tests
},
},
);