From 747fad0e06e73155616df62575626f7953260dec Mon Sep 17 00:00:00 2001 From: Akul Srivastava Date: Wed, 3 May 2023 19:10:17 +0530 Subject: [PATCH] [Fix] `no-unused-prop-types`: allow using spread with object expression in jsx Fixes #3566 --- CHANGELOG.md | 2 ++ lib/util/usedPropTypes.js | 2 +- tests/lib/rules/no-unused-prop-types.js | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af9b441a12..10dd5846e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,10 +19,12 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange * [`no-unknown-property`]: allow `fill` prop on `` ([#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 diff --git a/lib/util/usedPropTypes.js b/lib/util/usedPropTypes.js index 3597bb4010..6a0a650333 100644 --- a/lib/util/usedPropTypes.js +++ b/lib/util/usedPropTypes.js @@ -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', }); }, diff --git a/tests/lib/rules/no-unused-prop-types.js b/tests/lib/rules/no-unused-prop-types.js index c83be21f2d..c80c37f4cf 100644 --- a/tests/lib/rules/no-unused-prop-types.js +++ b/tests/lib/rules/no-unused-prop-types.js @@ -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 = ({ foo }) => { + return
{foo}
; + }; + + export default Demo; + `, + features: ['ts', 'no-babel'], + errors: [ + { message: '\'bar\' PropType is defined but prop is never used' }, + ], } )), });