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

Regression in prop-types rule in v5.1.1 #591

Closed
EvHaus opened this issue May 10, 2016 · 2 comments
Closed

Regression in prop-types rule in v5.1.1 #591

EvHaus opened this issue May 10, 2016 · 2 comments
Labels

Comments

@EvHaus
Copy link
Collaborator

EvHaus commented May 10, 2016

After upgrading from 5.0.1 to 5.1.1 I noticed a bug with the prop-types rule. It now incorrectly detects destructured method params as missing props. See example below:

export default (ComposedComponent) => class Something extends SomeOtherComponent {
    someMethod = ({width}) => {
        this.setState({width});
    }
}

Will result in an incorrect failure of: react/prop-types: 'width' is missing in props validation.

What's strange is that all of the examples below do NOT fail:

// Removed destructured function param
export default (ComposedComponent) => class Something extends SomeOtherComponent {
    someMethod = (width) => {
        this.setState({width});
    }
}

// Kept destructured function param but extend the class via `Component` instead
export default (ComposedComponent) => class Something extends Component {
    someMethod = ({width}) => {
        this.setState({width});
    }
}

// Kept destructured function param, and the custom class extend,
// but removed the composed function wrapper
export default class Something extends SomeOtherComponent {
    someMethod = ({width}) => {
        this.setState({width});
    }
}

Seems like the combination of a destructured function param, a HOC composed function wrapper and extending from a non-Component class causes a failure of the rule.

@EvHaus EvHaus changed the title Regression in prop-types rules in v5.1.1 Regression in prop-types rule in v5.1.1 May 10, 2016
@strawbrary
Copy link

Not sure if this is the same issue, but I've been having a similar issue with decorators and destructured params when wrapped with an array and/or object.

The following results in error 'store' is missing in props validation react/prop-types.

@asyncConnect([{
  promise: ({ store: { dispatch } }) => {
    return dispatch(fetchUsers());
  },
}])

The following do not trigger errors.

// No error if function isn't wrapped by an object and/or array
@asyncConnect(
  ({ store: { dispatch } }) => {
    return dispatch(fetchUsers());
  }
)

// No error after moving destructuring into function body
@asyncConnect([{
  promise: (params) => {
    const { store: { dispatch } } = params;
    return dispatch(fetchUsers());
  },
}])

@yannickcr
Copy link
Member

After some tests the regression seems to come from 4e1bcc0 so it should be here since v4.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants