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
Handle nodes without init #1611
Conversation
``` TypeError: Cannot read property 'type' of undefined at ObjectPattern (/Users/patrick/dev/sigopt-api/node_modules/eslint-plugin-react/lib/rules/no-access-state-in-setstate.js:158:52) at listeners.(anonymous function).forEach.listener (/Users/patrick/dev/sigopt-api/node_modules/eslint/lib/util/safe-emitter.js:47:58) at Array.forEach (<anonymous>) at Object.emit (/Users/patrick/dev/sigopt-api/node_modules/eslint/lib/util/safe-emitter.js:47:38) at NodeEventGenerator.applySelector (/Users/patrick/dev/sigopt-api/node_modules/eslint/lib/util/node-event-generator.js:251:26) at NodeEventGenerator.applySelectors (/Users/patrick/dev/sigopt-api/node_modules/eslint/lib/util/node-event-generator.js:280:22) at NodeEventGenerator.enterNode (/Users/patrick/dev/sigopt-api/node_modules/eslint/lib/util/node-event-generator.js:294:14) at CodePathAnalyzer.enterNode (/Users/patrick/dev/sigopt-api/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:608:23) at Traverser.enter (/Users/patrick/dev/sigopt-api/node_modules/eslint/lib/linter.js:956:32) at Traverser.__execute (/Users/patrick/dev/sigopt-api/node_modules/estraverse/estraverse.js:397:31) ```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks; this is great - could you also include a regression test, so it doesn't happen again?
While I would love to, to be clear this was the state of the codebase when I checked it out. I don't really know what caused the error or how to reproduce, but this did fix the issue and seems worth checking in to resolve the issue for future developers |
@pfhayes i'm confused; you're saying that |
I observed this when running eslint-plugin-react master on our company's codebase, and the actual case that causes this was hard to track down |
A test that would crash before this change is an SFC using destructuring in the parameters. |
Would you be interested in software that automatically finds TypeErrors like this? I am building Fuzz Stati0n to do that (free for OSS) - please take a look and consider signing up for our newsletter to keep in touch. |
@grajagandev do you mean any unchecked property accesses? Generally in eslint plugins, eslint is supposed to provide some guarantees in the node structures returned, so there'll be tons of them in this repo that aren't a problem. What would be most useful is something that knows about eslint/babel-eslint node types, and warns when those accesses are incorrect. |
Thank you - great feedback. We instrument the code and run Your suggestion makes me think that it could be smarter - we are very early stage so your input means a lot. |
Thanks, I confirmed the trigger on my end was object destructuring in function params and added a test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming the test fails without the fix, LGTM!
Avoids this error which appears in
master
in theno-access-state-in-setstate
rule