Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] prop-types: handle RestElement in destructured param #2805

Merged
merged 1 commit into from Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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