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

rule: forbid-prop-types, handle situation where getFirstTokens() call returns only 1 Token #377

Merged
merged 1 commit into from
Dec 30, 2015

Conversation

nfcampos
Copy link
Contributor

if you run eslint test.jsx

//test.jsx
class A {
  const
}

with

//.eslintrc
{
  "parser": "babel-eslint",
  "ecmaFeatures": {
    "jsx": true
  },
  "rules": {
    "react/forbid-prop-types": 1,
  },
  "plugins": [
    "react"
  ]
}

you get the following output

/Users/nuno/cp/james/node_modules/eslint-plugin-react/lib/rules/forbid-prop-types.js:38
        if (tokens[0].value === 'propTypes' || tokens[1].value === 'propTypes') {
                                                        ^

TypeError: Cannot read property 'value' of undefined
    at isPropTypesDeclaration (/Users/nuno/cp/james/node_modules/eslint-plugin-react/lib/rules/forbid-prop-types.js:38:19)
    at EventEmitter.ClassProperty (/Users/nuno/cp/james/node_modules/eslint-plugin-react/lib/rules/forbid-prop-types.js:87:11)
    at emitOne (events.js:77:13)
    at EventEmitter.emit (events.js:169:7)
    at NodeEventGenerator.enterNode (/Users/nuno/cp/james/node_modules/eslint/lib/util/node-event-generator.js:42:22)
    at CommentEventGenerator.enterNode (/Users/nuno/cp/james/node_modules/eslint/lib/util/comment-event-generator.js:98:23)

    at Controller.controller.traverse.enter (/Users/nuno/cp/james/node_modules/eslint/lib/eslint.js:767:36)
    at Controller.__execute (/Users/nuno/cp/james/node_modules/estraverse/estraverse.js:397:31)
    at Controller.traverse (/Users/nuno/cp/james/node_modules/estraverse/estraverse.js:495:28)
    at EventEmitter.module.exports.api.verify (/Users/nuno/cp/james/node_modules/eslint/lib/eslint.js:764:24)

because tokens is

[ Token {
    type: 'Keyword',
    value: 'const',
    start: 12,
    end: 17,
    loc: SourceLocation { start: [Object], end: [Object] },
    range: [ 12, 17 ] } ]

PS: (not sure whether we should also test for tokens[0] in the same fashion)
PPS: i know that first file is non-sensical javascript, this bug manifests itself when eslint is run continuously (eg. with the atom plugin linter-eslint), imagine that line saying const as what the linter sees when i'm midway writing constructor

handle situation where getFirstTokens() call returns only 1 Token
yannickcr added a commit that referenced this pull request Dec 30, 2015
Fix crash in forbid-prop-types
@yannickcr yannickcr merged commit de6f79c into jsx-eslint:master Dec 30, 2015
@yannickcr
Copy link
Member

Merged, thanks!

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

Successfully merging this pull request may close these issues.

2 participants