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 crash when using Unions in flow propTypes #1563

Merged

Conversation

justinanastos
Copy link
Contributor

@justinanastos justinanastos commented Nov 22, 2017

This will fix the crash when using Union flowtypes for the following rules:

  • prop-types
  • no-unused-prop-types

The library already escapes early when facing a typeNode it doesn't recognize; this will escape early when we can't even figure out the typeNode because UnionTypeAnnotations don't have an annotation.id.

This will not actually resolve the issue of using unions; it will simply prevent eslint from crashing.

Fixes issue #1468

@justinanastos justinanastos changed the title Fix crash when using Intersections in flow propTypes Fix crash when using Unions in flow propTypes Nov 22, 2017
Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ljharb ljharb merged commit df17cd4 into jsx-eslint:master Nov 22, 2017
@jseminck
Copy link
Contributor

This seems to work, but it would be nice to also have some test with some imported type that is used with union, like the main one reported from the issue. WDYT?

import type { FieldProps } from "redux-form"
type Props = {
  name: string,
} & FieldProps;

class Hello extends React.Component {
  props: Props;
  render() {
    const {name} = this.props;
    return name;
  }
}

@ljharb
Copy link
Member

ljharb commented Nov 23, 2017

@jseminck that's a great idea :-) more tests is always better!

@justinanastos
Copy link
Contributor Author

Absolutely agree! I’ll send an MR with another test with an import in the morning.

@ljharb
Copy link
Member

ljharb commented Nov 24, 2017

Thanks, a PR would be great (not sure what an MR is)

@justinanastos
Copy link
Contributor Author

justinanastos commented Nov 24, 2017

Sorry @ljharb , been spending too much time using GitLab (merge request versus pull request).

@justinanastos
Copy link
Contributor Author

justinanastos commented Nov 24, 2017

I created a new PR with additional tests (#1570).

@jseminck I want to point out that this does not actually apply the rules with the imports or the union propTypes in the previous PR; this just prevents eslint from crashing.

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

Successfully merging this pull request may close these issues.

None yet

3 participants