Skip to content

Commit

Permalink
[Fix] no-unused-prop-types: allow using spread with object expressi…
Browse files Browse the repository at this point in the history
…on in jsx

Fixes #3566
  • Loading branch information
akulsr0 authored and ljharb committed May 3, 2023
1 parent 13f5c19 commit 747fad0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -19,10 +19,12 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
* [`no-unknown-property`]: allow `fill` prop on `<symbol>` ([#3555][] @stefanprobst)
* [`display-name`], [`prop-types`]: when checking for a capitalized name, ignore underscores entirely ([#3560][] @ljharb)
* [`no-unused-state`]: avoid crashing on a class field function with destructured state ([#3568][] @ljharb)
* [`no-unused-prop-types`]: allow using spread with object expression in jsx ([#3570][] @akulsr0)

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

[#3570]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3570
[#3568]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3568
[#3563]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3563
[#3560]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3560
Expand Down
2 changes: 1 addition & 1 deletion lib/util/usedPropTypes.js
Expand Up @@ -534,7 +534,7 @@ module.exports = function usedPropTypesInstructions(context, components, utils)
JSXSpreadAttribute(node) {
const component = components.get(utils.getParentComponent());
components.set(component ? component.node : node, {
ignoreUnusedPropTypesValidation: true,
ignoreUnusedPropTypesValidation: node.argument.type !== 'ObjectExpression',
});
},

Expand Down
20 changes: 20 additions & 0 deletions tests/lib/rules/no-unused-prop-types.js
Expand Up @@ -6689,6 +6689,26 @@ ruleTester.run('no-unused-prop-types', rule, {
{ message: '\'foo\' PropType is defined but prop is never used' },
{ message: '\'propTypes\' PropType is defined but prop is never used' },
],
},
{
code: `
import React from "react";
type props = {
foo: string;
bar: string;
};
const Demo: React.FC<props> = ({ foo }) => {
return <div {...{}}>{foo}</div>;
};
export default Demo;
`,
features: ['ts', 'no-babel'],
errors: [
{ message: '\'bar\' PropType is defined but prop is never used' },
],
}
)),
});

0 comments on commit 747fad0

Please sign in to comment.