Skip to content

Commit 39307b4

Browse files
hank121314ljharb
authored andcommitted
[Fix] prop-types: handle RestElement in destructured param
Fixes #2804.
1 parent 8edb880 commit 39307b4

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
55

66
## Unreleased
77

8+
### Fixed
9+
* [`prop-types`]: handle RestElement in destructured param ([#2805][] @hank121314)
10+
11+
[#2805]: https://github.com/yannickcr/eslint-plugin-react/pull/2805
12+
813
## [7.21.1] - 2020.09.23
914

1015
### Fixed

lib/rules/prop-types.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ module.exports = {
150150
return;
151151
}
152152
param.properties.forEach((property) => {
153+
if (property.type === 'RestElement') {
154+
return;
155+
}
153156
const type = property.value.type;
154157
const right = property.value.right;
155158
if (type !== 'AssignmentPattern') {

tests/lib/rules/prop-types.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3109,6 +3109,40 @@ ruleTester.run('prop-types', rule, {
31093109
type StateProps = ReturnType<typeof mapStateToProps>
31103110
type DispatchProps = ReturnType<typeof mapDispatchToProps>`,
31113111
parser: parsers['@TYPESCRIPT_ESLINT']
3112+
},
3113+
{
3114+
code: `
3115+
import React from 'react'
3116+
3117+
interface Meta {
3118+
touched: boolean,
3119+
error: string;
3120+
}
3121+
3122+
interface Props {
3123+
input: string,
3124+
meta: Meta,
3125+
cssClasses: object
3126+
}
3127+
const InputField = ({ input, meta: { touched, error }, cssClasses = {}, ...restProps }: Props) => {
3128+
restProps.className = cssClasses.base
3129+
3130+
if (cssClasses.custom) {
3131+
restProps.className += 'cssClasses.custom'
3132+
}
3133+
if (touched && error) {
3134+
restProps.className += 'cssClasses.error'
3135+
}
3136+
3137+
return(
3138+
<input
3139+
{...input}
3140+
{...restProps}
3141+
/>
3142+
)
3143+
}
3144+
export default InputField`,
3145+
parser: parsers['@TYPESCRIPT_ESLINT']
31123146
}
31133147
])
31143148
),

0 commit comments

Comments
 (0)