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

Error in prop-types rule: key is undefined #269

Closed
tkers opened this issue Oct 22, 2015 · 5 comments
Closed

Error in prop-types rule: key is undefined #269

tkers opened this issue Oct 22, 2015 · 5 comments

Comments

@tkers
Copy link

tkers commented Oct 22, 2015

We just encountered an error in the prop-types rule while ESLinting a JSX file. I'm unable to share the full source, but will try to pinpoint the part where the rule fails exactly.

In the meantime, this is the full stack trace:

/usr/local/lib/node_modules/eslint-plugin-react/lib/rules/prop-types.js:187
return key.type === 'Identifier' ? key.name : key.value;
             ^

TypeError: Cannot read property 'type' of undefined
   at getKeyValue (/usr/local/lib/node_modules/eslint-plugin-react/lib/rules/prop-types.js:187:15)
   at markPropTypesAsUsed (/usr/local/lib/node_modules/eslint-plugin-react/lib/rules/prop-types.js:366:11)
   at EventEmitter.MemberExpression (/usr/local/lib/node_modules/eslint-plugin-react/lib/rules/prop-types.js:547:11)
   at emitOne (events.js:82:20)
   at EventEmitter.emit (events.js:169:7)
   at NodeEventGenerator.enterNode (/usr/local/lib/node_modules/eslint/lib/util/node-event-generator.js:42:22)
   at CommentEventGenerator.enterNode (/usr/local/lib/node_modules/eslint/lib/util/comment-event-generator.js:98:23)
   at Controller.controller.traverse.enter (/usr/local/lib/node_modules/eslint/lib/eslint.js:782:36)
   at Controller.__execute (/usr/local/lib/node_modules/eslint/node_modules/estraverse/estraverse.js:397:31)
   at Controller.traverse (/usr/local/lib/node_modules/eslint/node_modules/estraverse/estraverse.js:495:28)

Also, ESLint exited with code 0 in the end, which to me looks not really desirable if one of the rules fails, although I assume that's more of an issue of ESLint itself.

@yannickcr
Copy link
Member

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 ?

@tkers
Copy link
Author

tkers commented Oct 27, 2015

So the problem seems to be specifically related to the rest spread feature we use in our JSX files:

let { firstKey, ...rest } = this.props;

Works fine. But this:

let { ...rest } = this.props;

Results in the TypeError as shown in my first post.

I've seen some other issues (eslint/eslint#3271) regarding the experimentalObjectRestSpread feature in the ESLint repository itself, (e.g. using <ComponentName {...other} prop={firstKey} /> reports other as not defined), so this might actually be related.

However, I'm pretty sure the prop-types check shouldn't break like this.

@yannickcr
Copy link
Member

I was not able to reproduce the error, but it should be fixed in v3.7.1.

If it is not the case, re-open this issue and add the complete code sample that trigger the crash.

@tkers
Copy link
Author

tkers commented Nov 12, 2015

Hey, sorry to get back at you this late. I was able to reproduce this bug here: Lapixx/a30830afe8408756d254

Running eslint 1.5.1 and eslint-plugin-react 3.8.0

@yannickcr
Copy link
Member

Thanks for your test case, I can reproduce it now.
I will fix this.

@yannickcr yannickcr reopened this Nov 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants