Skip to content

Commit 747fad0

Browse files
akulsr0ljharb
authored andcommitted
[Fix] no-unused-prop-types: allow using spread with object expression in jsx
Fixes #3566
1 parent 13f5c19 commit 747fad0

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1919
* [`no-unknown-property`]: allow `fill` prop on `<symbol>` ([#3555][] @stefanprobst)
2020
* [`display-name`], [`prop-types`]: when checking for a capitalized name, ignore underscores entirely ([#3560][] @ljharb)
2121
* [`no-unused-state`]: avoid crashing on a class field function with destructured state ([#3568][] @ljharb)
22+
* [`no-unused-prop-types`]: allow using spread with object expression in jsx ([#3570][] @akulsr0)
2223

2324
### Changed
2425
* [Docs] [`jsx-newline`], [`no-unsafe`], [`static-property-placement`]: Fix code syntax highlighting ([#3563][] @nbsp1221)
2526

27+
[#3570]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3570
2628
[#3568]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3568
2729
[#3563]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3563
2830
[#3560]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3560

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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6689,6 +6689,26 @@ 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+
code: `
6695+
import React from "react";
6696+
6697+
type props = {
6698+
foo: string;
6699+
bar: string;
6700+
};
6701+
6702+
const Demo: React.FC<props> = ({ foo }) => {
6703+
return <div {...{}}>{foo}</div>;
6704+
};
6705+
6706+
export default Demo;
6707+
`,
6708+
features: ['ts', 'no-babel'],
6709+
errors: [
6710+
{ message: '\'bar\' PropType is defined but prop is never used' },
6711+
],
66926712
}
66936713
)),
66946714
});

0 commit comments

Comments
 (0)