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

Crash in forbid-prop-types #230

Closed
epmatsw opened this issue Sep 28, 2015 · 7 comments
Closed

Crash in forbid-prop-types #230

epmatsw opened this issue Sep 28, 2015 · 7 comments
Labels

Comments

@epmatsw
Copy link
Contributor

epmatsw commented Sep 28, 2015

I'm getting a crash on line 65 of forbid-prop-types.js. Cannot read property 'name' of undefined. My guess is that the line above (declaration.value = declaration.value.object;) is storing an object without a property value, which then crashes. It could probably be fixed by just doing an existence check, but I'm not entirely sure that there isn't an upstream issue that's the root cause.

@epmatsw
Copy link
Contributor Author

epmatsw commented Sep 28, 2015

I'm also unfortunately not sure what code exactly is triggering this. It's coming from somewhere in our gulp-eslint process, which makes it a bit hard to track down :/

@yannickcr
Copy link
Member

Thanks for the report, I'll try to fix this ASAP.

It would be a great help for us if you can track down the code responsible for the crash, maybe by running ESLint on one directory at a time until you find the file that trigger this error ?

@yannickcr yannickcr added the bug label Sep 28, 2015
@epmatsw
Copy link
Contributor Author

epmatsw commented Sep 29, 2015

I think I've figured it out. We're destructuring React to get {PropTypes}, so the propTypes that triggers the crash looks like:

propTypes: {
        items: PropTypes.arrayOf(PropTypes.object).isRequired,
        renderCard: PropTypes.func.isRequired,
        actions: PropTypes.object,
        multiActions: PropTypes.object
      }

I would guess that the plugin expects only React.PropTypes, which causes the error.

@epmatsw
Copy link
Contributor Author

epmatsw commented Sep 29, 2015

Then again, maybe not. Changing to React.PropTypes did not seem to fix it.

@chollier
Copy link

I'm getting the same issue, this code makes it crash :

  static propTypes = {
    retailer: PropTypes.instanceOf(Map).isRequired,
    requestRetailer: PropTypes.func.isRequired
  }

this code doesn't :

  static propTypes = {
    // retailer: PropTypes.instanceOf(Map).isRequired,
    requestRetailer: PropTypes.func.isRequired
  }

@epmatsw
Copy link
Contributor Author

epmatsw commented Sep 30, 2015

Not entirely fixed it seems.

React.createClass({
  propTypes: {
    options: optionsType
  }
});

yannickcr added a commit that referenced this issue Oct 6, 2015
Fix crash with destructured PropTypes (fixes #230)
@naddeoa
Copy link

naddeoa commented Oct 18, 2015

Found another example to contribute. This doesn't work:

var optionPropType = {
    value: React.PropTypes.string.isRequired,
    label: React.PropTypes.string.isRequired
};

var DropdownView = React.createClass({
    propTypes: {
        widthNamed: Dropdown.propTypes.width,
        optionPrompt: React.PropTypes.string,
        selected: optionPropType,
        options: React.PropTypes.arrayOf(React.PropTypes.shape(optionPropType))
    }
});

Then, I noticed that I was actually passing in a plain object to propTypes.selected. I made optionPropType a React.propType.shape and that fixed it:

var optionPropType = React.PropTypes.shape({
    value: React.PropTypes.string.isRequired,
    label: React.PropTypes.string.isRequired
});

var DropdownView = React.createClass({
    propTypes: {
        widthNamed: Dropdown.propTypes.width,
        optionPrompt: React.PropTypes.string,
        selected: optionPropType,
        options: React.PropTypes.arrayOf(optionPropType)
    }
});

EDIT:
Spoke too soon, that didn't work. Doing this did though:

var DropdownView = React.createClass({
    propTypes: {
        widthNamed: Dropdown.propTypes.width,
        optionPrompt: React.PropTypes.string,
        selected: React.PropTypes.shape({
            value: React.PropTypes.string.isRequired,
            label: React.PropTypes.string.isRequired
        }),
        options: React.PropTypes.arrayOf(Dropdown.propTypes.option)
    },
});

I guess the issue is just with referencing objects defined in the same file?

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

4 participants