Skip to content

Commit

Permalink
fix lint plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp committed Jun 13, 2024
1 parent d2ddf3b commit 37c6c5d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,9 @@ const rule = {

return {
CallExpression(node) {
const isCreateUseThemePropsCall = node.callee.name === 'createUseThemeProps';
if (isCreateUseThemePropsCall) {
if (!node.arguments.length) {
context.report({ node, messageId: 'noNameValue' });
} else if (node.arguments[0].type !== 'Literal' || !node.arguments[0].value) {
context.report({ node: node.arguments[0], messageId: 'noNameValue' });
}
}

let nameLiteral = null;
const isUseThemePropsCall = node.callee.name === 'useThemeProps';
if (isUseThemePropsCall) {
const isUseDefaultPropsCall = node.callee.name === 'useDefaultProps';
if (isUseDefaultPropsCall) {
let isCalledFromCustomHook = false;
let parent = node.parent;
while (parent != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ ruleTester.run('mui-name-matches-component-name', rule, {
inProps: StaticDateRangePickerProps<TDate>,
ref: React.Ref<HTMLDivElement>,
) {
const props = useThemeProps({ props: inProps, name: 'MuiStaticDateRangePicker' });
const props = useDefaultProps({ props: inProps, name: 'MuiStaticDateRangePicker' });
});
`,
`
function CssBaseline(inProps) {
useThemeProps({ props: inProps, name: 'MuiCssBaseline' });
useDefaultProps({ props: inProps, name: 'MuiCssBaseline' });
}
`,
`
Expand All @@ -32,7 +32,7 @@ ruleTester.run('mui-name-matches-component-name', rule, {
];
},
}),
useThemeProps: (inProps) => useThemeProps({ props: inProps, name: 'MuiContainer' }),
useDefaultProps: (inProps) => useDefaultProps({ props: inProps, name: 'MuiContainer' }),
});
`,
`
Expand All @@ -42,12 +42,9 @@ ruleTester.run('mui-name-matches-component-name', rule, {
overridesResolver: (props, styles) => styles.root,
}),
componentName: 'MuiGrid2',
useThemeProps: (inProps) => useThemeProps({ props: inProps, name: 'MuiGrid2' }),
useDefaultProps: (inProps) => useDefaultProps({ props: inProps, name: 'MuiGrid2' }),
}) as OverridableComponent<Grid2TypeMap>;
`,
`
const useThemeProps = createUseThemeProps('MuiBadge');
`,
{
code: `
const StaticDateRangePicker = React.forwardRef(function StaticDateRangePicker<TDate>(
Expand All @@ -62,7 +59,7 @@ ruleTester.run('mui-name-matches-component-name', rule, {
{
code: `
function useDatePickerDefaultizedProps(props, name) {
useThemeProps({ props, name });
useDefaultProps({ props, name });
}
`,
options: [{ customHooks: ['useDatePickerDefaultizedProps'] }],
Expand All @@ -75,7 +72,7 @@ ruleTester.run('mui-name-matches-component-name', rule, {
inProps: StaticDateRangePickerProps<TDate>,
ref: React.Ref<HTMLDivElement>,
) {
const props = useThemeProps({ props: inProps, name: 'MuiPickersDateRangePicker' });
const props = useDefaultProps({ props: inProps, name: 'MuiPickersDateRangePicker' });
});
`,
errors: [
Expand All @@ -87,7 +84,7 @@ ruleTester.run('mui-name-matches-component-name', rule, {
],
},
{
code: 'useThemeProps({ props: inProps })',
code: 'useDefaultProps({ props: inProps })',
errors: [
{
message: 'Unable to find `name` property. Did you forget to pass `name`?',
Expand All @@ -96,7 +93,7 @@ ruleTester.run('mui-name-matches-component-name', rule, {
],
},
{
code: 'useThemeProps({ props: inProps, name })',
code: 'useDefaultProps({ props: inProps, name })',
errors: [
{
message:
Expand All @@ -106,7 +103,7 @@ ruleTester.run('mui-name-matches-component-name', rule, {
],
},
{
code: "useThemeProps({ props: inProps, name: 'MuiPickersDateRangePicker' })",
code: "useDefaultProps({ props: inProps, name: 'MuiPickersDateRangePicker' })",
errors: [{ message: 'Unable to find component for this call.', type: 'CallExpression' }],
},
{
Expand Down Expand Up @@ -145,37 +142,5 @@ ruleTester.run('mui-name-matches-component-name', rule, {
},
],
},
{
code: `
const useThemeProps = createUseThemeProps();
const Badge = React.forwardRef(function Badge(inProps, ref) {
const props = useThemeProps({ props: inProps, name: 'MuiBadge' });
});
`,
errors: [
{
message:
'Unable to resolve `name`. Please hardcode the `name` i.e. use a string literal.',
type: 'CallExpression',
},
],
},
{
code: `
const useThemeProps = createUseThemeProps({ name: 'MuiBadge' });
const Badge = React.forwardRef(function Badge(inProps, ref) {
const props = useThemeProps({ props: inProps, name: 'MuiBadge' });
});
`,
errors: [
{
message:
'Unable to resolve `name`. Please hardcode the `name` i.e. use a string literal.',
type: 'ObjectExpression',
},
],
},
],
});

0 comments on commit 37c6c5d

Please sign in to comment.