Skip to content

Commit

Permalink
[Fix] prop-types: handle RestElement in destructured param
Browse files Browse the repository at this point in the history
Fixes #2804.
  • Loading branch information
hank121314 authored and ljharb committed Sep 24, 2020
1 parent 8edb880 commit 39307b4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/rules/prop-types.js
Expand Up @@ -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') {
Expand Down
34 changes: 34 additions & 0 deletions tests/lib/rules/prop-types.js
Expand Up @@ -3109,6 +3109,40 @@ ruleTester.run('prop-types', rule, {
type StateProps = ReturnType<typeof mapStateToProps>
type DispatchProps = ReturnType<typeof mapDispatchToProps>`,
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(
<input
{...input}
{...restProps}
/>
)
}
export default InputField`,
parser: parsers['@TYPESCRIPT_ESLINT']
}
])
),
Expand Down

0 comments on commit 39307b4

Please sign in to comment.