@@ -4,6 +4,7 @@ const rule = require('./mui-name-matches-component-name');
4
4
const ruleTester = new eslint . RuleTester ( { parser : require . resolve ( '@typescript-eslint/parser' ) } ) ;
5
5
ruleTester . run ( 'mui-name-matches-component-name' , rule , {
6
6
valid : [
7
+ // useThemeProps
7
8
`
8
9
const StaticDateRangePicker = React.forwardRef(function StaticDateRangePicker<TDate>(
9
10
inProps: StaticDateRangePickerProps<TDate>,
@@ -45,8 +46,56 @@ ruleTester.run('mui-name-matches-component-name', rule, {
45
46
useThemeProps: (inProps) => useThemeProps({ props: inProps, name: 'MuiGrid2' }),
46
47
}) as OverridableComponent<Grid2TypeMap>;
47
48
` ,
49
+ {
50
+ code : `
51
+ function useDatePickerDefaultizedProps(props, name) {
52
+ useThemeProps({ props, name });
53
+ }
54
+ ` ,
55
+ options : [ { customHooks : [ 'useDatePickerDefaultizedProps' ] } ] ,
56
+ } ,
57
+ // ================
58
+ // useDefaultProps
59
+ `
60
+ const StaticDateRangePicker = React.forwardRef(function StaticDateRangePicker<TDate>(
61
+ inProps: StaticDateRangePickerProps<TDate>,
62
+ ref: React.Ref<HTMLDivElement>,
63
+ ) {
64
+ const props = useDefaultProps({ props: inProps, name: 'MuiStaticDateRangePicker' });
65
+ });
66
+ ` ,
48
67
`
49
- const useThemeProps = createUseThemeProps('MuiBadge');
68
+ function CssBaseline(inProps) {
69
+ useDefaultProps({ props: inProps, name: 'MuiCssBaseline' });
70
+ }
71
+ ` ,
72
+ `
73
+ const Container = createContainer({
74
+ createStyledComponent: styled('div', {
75
+ name: 'MuiContainer',
76
+ slot: 'Root',
77
+ overridesResolver: (props, styles) => {
78
+ const { ownerState } = props;
79
+
80
+ return [
81
+ styles.root,
82
+ ownerState.fixed && styles.fixed,
83
+ ownerState.disableGutters && styles.disableGutters,
84
+ ];
85
+ },
86
+ }),
87
+ useDefaultProps: (inProps) => useDefaultProps({ props: inProps, name: 'MuiContainer' }),
88
+ });
89
+ ` ,
90
+ `
91
+ const Grid2 = createGrid2({
92
+ createStyledComponent: styled('div', {
93
+ name: 'MuiGrid2',
94
+ overridesResolver: (props, styles) => styles.root,
95
+ }),
96
+ componentName: 'MuiGrid2',
97
+ useDefaultProps: (inProps) => useDefaultProps({ props: inProps, name: 'MuiGrid2' }),
98
+ }) as OverridableComponent<Grid2TypeMap>;
50
99
` ,
51
100
{
52
101
code : `
@@ -62,13 +111,14 @@ ruleTester.run('mui-name-matches-component-name', rule, {
62
111
{
63
112
code : `
64
113
function useDatePickerDefaultizedProps(props, name) {
65
- useThemeProps ({ props, name });
114
+ useDefaultProps ({ props, name });
66
115
}
67
116
` ,
68
117
options : [ { customHooks : [ 'useDatePickerDefaultizedProps' ] } ] ,
69
118
} ,
70
119
] ,
71
120
invalid : [
121
+ // useThemeProps
72
122
{
73
123
code : `
74
124
const StaticDateRangePicker = React.forwardRef(function StaticDateRangePicker<TDate>(
@@ -115,28 +165,29 @@ ruleTester.run('mui-name-matches-component-name', rule, {
115
165
inProps: StaticDateRangePickerProps<TDate>,
116
166
ref: React.Ref<HTMLDivElement>,
117
167
) {
118
- const props = useDatePickerDefaultizedProps(inProps);
168
+ const props = useDatePickerDefaultizedProps(inProps, 'MuiPickersDateRangePicker' );
119
169
});
120
170
` ,
121
171
options : [ { customHooks : [ 'useDatePickerDefaultizedProps' ] } ] ,
122
172
errors : [
123
173
{
124
174
message :
125
- "Unable to find name argument. Expected `useDatePickerDefaultizedProps(firstParameter, 'MuiComponent')` ." ,
126
- type : 'Identifier ' ,
175
+ "Expected `name` to be 'MuiStaticDateRangePicker' but instead got 'MuiPickersDateRangePicker' ." ,
176
+ type : 'Literal ' ,
127
177
} ,
128
178
] ,
129
179
} ,
180
+ // ================
181
+ // useDefaultProps
130
182
{
131
183
code : `
132
184
const StaticDateRangePicker = React.forwardRef(function StaticDateRangePicker<TDate>(
133
185
inProps: StaticDateRangePickerProps<TDate>,
134
186
ref: React.Ref<HTMLDivElement>,
135
187
) {
136
- const props = useDatePickerDefaultizedProps( inProps, 'MuiPickersDateRangePicker');
188
+ const props = useDefaultProps({ props: inProps, name: 'MuiPickersDateRangePicker' } );
137
189
});
138
190
` ,
139
- options : [ { customHooks : [ 'useDatePickerDefaultizedProps' ] } ] ,
140
191
errors : [
141
192
{
142
193
message :
@@ -145,35 +196,64 @@ ruleTester.run('mui-name-matches-component-name', rule, {
145
196
} ,
146
197
] ,
147
198
} ,
199
+ {
200
+ code : 'useDefaultProps({ props: inProps })' ,
201
+ errors : [
202
+ {
203
+ message : 'Unable to find `name` property. Did you forget to pass `name`?' ,
204
+ type : 'ObjectExpression' ,
205
+ } ,
206
+ ] ,
207
+ } ,
208
+ {
209
+ code : 'useDefaultProps({ props: inProps, name })' ,
210
+ errors : [
211
+ {
212
+ message :
213
+ 'Unable to resolve `name`. Please hardcode the `name` i.e. use a string literal.' ,
214
+ type : 'Identifier' ,
215
+ } ,
216
+ ] ,
217
+ } ,
218
+ {
219
+ code : "useDefaultProps({ props: inProps, name: 'MuiPickersDateRangePicker' })" ,
220
+ errors : [ { message : 'Unable to find component for this call.' , type : 'CallExpression' } ] ,
221
+ } ,
148
222
{
149
223
code : `
150
- const useThemeProps = createUseThemeProps();
151
-
152
- const Badge = React.forwardRef(function Badge(inProps, ref) {
153
- const props = useThemeProps({ props: inProps, name: 'MuiBadge' });
224
+ const StaticDateRangePicker = React.forwardRef(function StaticDateRangePicker<TDate>(
225
+ inProps: StaticDateRangePickerProps<TDate>,
226
+ ref: React.Ref<HTMLDivElement>,
227
+ ) {
228
+ const props = useDatePickerDefaultizedProps(inProps);
154
229
});
155
230
` ,
231
+ options : [ { customHooks : [ 'useDatePickerDefaultizedProps' ] } ] ,
156
232
errors : [
157
233
{
158
234
message :
159
- ' Unable to resolve ` name`. Please hardcode the `name` i.e. use a string literal.' ,
160
- type : 'CallExpression ' ,
235
+ " Unable to find name argument. Expected `useDatePickerDefaultizedProps(firstParameter, 'MuiComponent')`." ,
236
+ type : 'Identifier ' ,
161
237
} ,
162
238
] ,
163
239
} ,
240
+ // ================
241
+ // customHooks
164
242
{
165
243
code : `
166
- const useThemeProps = createUseThemeProps({ name: 'MuiBadge' });
167
-
168
- const Badge = React.forwardRef(function Badge(inProps, ref) {
169
- const props = useThemeProps({ props: inProps, name: 'MuiBadge' });
244
+ const StaticDateRangePicker = React.forwardRef(function StaticDateRangePicker<TDate>(
245
+ inProps: StaticDateRangePickerProps<TDate>,
246
+ ref: React.Ref<HTMLDivElement>,
247
+ ) {
248
+ const props = useDatePickerDefaultizedProps(inProps, 'MuiPickersDateRangePicker');
170
249
});
171
250
` ,
251
+ options : [ { customHooks : [ 'useDatePickerDefaultizedProps' ] } ] ,
172
252
errors : [
173
253
{
174
254
message :
175
- 'Unable to resolve `name`. Please hardcode the `name` i.e. use a string literal.' ,
176
- type : 'ObjectExpression ' ,
255
+ "Expected `name` to be 'MuiStaticDateRangePicker' but instead got 'MuiPickersDateRangePicker'." ,
256
+ type : 'Literal ' ,
177
257
} ,
178
258
] ,
179
259
} ,
0 commit comments