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

Invalid propType definition crashes linter #95

Closed
LeZuse opened this issue Jun 5, 2015 · 2 comments
Closed

Invalid propType definition crashes linter #95

LeZuse opened this issue Jun 5, 2015 · 2 comments

Comments

@LeZuse
Copy link

LeZuse commented Jun 5, 2015

Using babel-eslint parser, this piece of invalid code (notice the colon instead of an equals sign):
static propTypes: { showCompletedReleases: PropTypes.bool.isRequired }
will crash the linter with this error:

[...]/node_modules/eslint-plugin-react/lib/rules/prop-types.js:165
    switch (propTypes.type) {
                     ^
TypeError: Cannot read property 'type' of null
    at markPropTypesAsDeclared (/Users/zuse/Projects/pb-frontend/node_modules/eslint-plugin-react/lib/rules/prop-types.js:165:22)
    at EventEmitter.ClassProperty (/Users/zuse/Projects/pb-frontend/node_modules/eslint-plugin-react/lib/rules/prop-types.js:220:7)
    at EventEmitter.emit (events.js:107:17)
    at Controller.controller.traverse.enter (/Users/zuse/Projects/pb-frontend/node_modules/eslint/lib/eslint.js:725:25)
    at Controller.__execute (/Users/zuse/Projects/pb-frontend/node_modules/eslint/node_modules/estraverse/estraverse.js:393:31)
    at Controller.traverse (/Users/zuse/Projects/pb-frontend/node_modules/eslint/node_modules/estraverse/estraverse.js:491:28)
    at EventEmitter.module.exports.api.verify (/Users/zuse/Projects/pb-frontend/node_modules/eslint/lib/eslint.js:718:24)
    at processFile (/Users/zuse/Projects/pb-frontend/node_modules/eslint/lib/cli-engine.js:197:27)
    at /Users/zuse/Projects/pb-frontend/node_modules/eslint/lib/cli-engine.js:332:26
    at /Users/zuse/Projects/pb-frontend/node_modules/eslint/lib/util/traverse.js:61:17
@BerkeleyTrue
Copy link

This may crash due to babel itself. Tried to see if babel would parse it. Seems like the REPL just hangs until corrected.

https://babeljs.io/repl

@yannickcr
Copy link
Member

Babel seems to accept the code but do not output the propTypes key in the compiled source, resulting in missing propTypes definition.

I've updated the rule to ignore the propTypes definition in this case, so you'll get an "propTypes missing" error if your propTypes definition is invalid.

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

No branches or pull requests

3 participants