Skip to content

Commit bc34683

Browse files
committed
fix: not showing error when using spread with object expression in jsx
1 parent 13f5c19 commit bc34683

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/util/usedPropTypes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ module.exports = function usedPropTypesInstructions(context, components, utils)
534534
JSXSpreadAttribute(node) {
535535
const component = components.get(utils.getParentComponent());
536536
components.set(component ? component.node : node, {
537-
ignoreUnusedPropTypesValidation: true,
537+
ignoreUnusedPropTypesValidation: !(node.argument.type === 'ObjectExpression'),
538538
});
539539
},
540540

tests/lib/rules/no-unused-prop-types.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6689,6 +6689,27 @@ ruleTester.run('no-unused-prop-types', rule, {
66896689
{ message: '\'foo\' PropType is defined but prop is never used' },
66906690
{ message: '\'propTypes\' PropType is defined but prop is never used' },
66916691
],
6692+
},
6693+
6694+
{
6695+
code: `
6696+
import React from "react";
6697+
6698+
type props = {
6699+
foo: string;
6700+
bar: string;
6701+
};
6702+
6703+
const Demo: React.FC<props> = ({ foo }) => {
6704+
return <div {...{}}>{foo}</div>;
6705+
};
6706+
6707+
export default Demo;
6708+
`,
6709+
features: ['ts'],
6710+
errors: [
6711+
{ message: '\'bar\' PropType is defined but prop is never used' },
6712+
],
66926713
}
66936714
)),
66946715
});

0 commit comments

Comments
 (0)