From 39307b46783f016892ef999410e87a6755b5426e Mon Sep 17 00:00:00 2001 From: Hank Chen Date: Thu, 24 Sep 2020 09:37:15 +0800 Subject: [PATCH] [Fix] `prop-types`: handle RestElement in destructured param Fixes #2804. --- CHANGELOG.md | 5 +++++ lib/rules/prop-types.js | 3 +++ tests/lib/rules/prop-types.js | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b8b955f8f..cba20746bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel ## Unreleased +### Fixed +* [`prop-types`]: handle RestElement in destructured param ([#2805][] @hank121314) + +[#2805]: https://github.com/yannickcr/eslint-plugin-react/pull/2805 + ## [7.21.1] - 2020.09.23 ### Fixed diff --git a/lib/rules/prop-types.js b/lib/rules/prop-types.js index ee939df065..6eec874a89 100644 --- a/lib/rules/prop-types.js +++ b/lib/rules/prop-types.js @@ -150,6 +150,9 @@ module.exports = { return; } param.properties.forEach((property) => { + if (property.type === 'RestElement') { + return; + } const type = property.value.type; const right = property.value.right; if (type !== 'AssignmentPattern') { diff --git a/tests/lib/rules/prop-types.js b/tests/lib/rules/prop-types.js index b68dafe534..0ef8a072f0 100644 --- a/tests/lib/rules/prop-types.js +++ b/tests/lib/rules/prop-types.js @@ -3109,6 +3109,40 @@ ruleTester.run('prop-types', rule, { type StateProps = ReturnType type DispatchProps = ReturnType`, parser: parsers['@TYPESCRIPT_ESLINT'] + }, + { + code: ` + import React from 'react' + + interface Meta { + touched: boolean, + error: string; + } + + interface Props { + input: string, + meta: Meta, + cssClasses: object + } + const InputField = ({ input, meta: { touched, error }, cssClasses = {}, ...restProps }: Props) => { + restProps.className = cssClasses.base + + if (cssClasses.custom) { + restProps.className += 'cssClasses.custom' + } + if (touched && error) { + restProps.className += 'cssClasses.error' + } + + return( + + ) + } + export default InputField`, + parser: parsers['@TYPESCRIPT_ESLINT'] } ]) ),