Skip to content
This repository has been archived by the owner on Aug 18, 2021. It is now read-only.

TypeError: Cannot read property 'match' of undefined #242

Closed
aweary opened this issue Jan 30, 2016 · 6 comments
Closed

TypeError: Cannot read property 'match' of undefined #242

aweary opened this issue Jan 30, 2016 · 6 comments

Comments

@aweary
Copy link

aweary commented Jan 30, 2016

We are getting this error after the latest babel-eslint 5.0.0-beta7. We are using the latests stable eslint release 1.10.3 and node 4.2.6

TypeError: Cannot read property 'match' of undefined
    at EventEmitter.removeInvalidNodeErrors (/home/travis/build/[path]/node_modules/eslint/lib/rules/no-irregular-whitespace.js:51:25)
    at emitOne (events.js:82:20)
    at EventEmitter.emit (events.js:169:7)
    at NodeEventGenerator.enterNode (/home/travis/build/[path]/node_modules/eslint/lib/util/node-event-generator.js:42:22)
    at CommentEventGenerator.enterNode (/home/travis/build/[path]/node_modules/eslint/lib/util/comment-event-generator.js:98:23)
    at Controller.controller.traverse.enter (/home/travis/build/[path]/node_modules/eslint/lib/eslint.js:767:36)
    at Controller.__execute (/home/travis/build/[path]/node_modules/eslint/node_modules/estraverse/estraverse.js:397:31)
    at Controller.traverse (/home/travis/build/[path]/node_modules/eslint/node_modules/estraverse/estraverse.js:495:28)
    at EventEmitter.module.exports.api.verify (/home/travis/build/[path]/node_modules/eslint/lib/eslint.js:764:24)
    at processText (/home/travis/build/[path]/node_modules/eslint/lib/cli-engine.js:230:27)

Our eslintConfig in our package.json is as follow:

  "eslintConfig": {
    "extends": "airbnb",
    "rules": {
      "comma-dangle": [
        2,
        "never"
      ],
      "no-trailing-spaces": [
        2,
        {
          "skipBlankLines": true
        }
      ],
      "block-spacing": [
        2,
        "never"
      ],
      "arrow-spacing": [
        2,
        {
          "before": true,
          "after": true
        }
      ],
      "space-in-parens": [
        2,
        "never"
      ],
      "space-before-function-paren": [
        2,
        "never"
      ],
      "space-before-blocks": [
        2,
        "always"
      ],
      "space-after-keywords": [
        2,
        "always"
      ],
      "react/jsx-quotes": 0,
      "jsx-quotes": 0,
      "react/react-in-jsx-scope": 0
    }
  },

The stack trace seems to point towards this if statement:

if (node.raw.match(irregularWhitespace) || node.raw.match(irregularLineTerminators)) {
   removeStringError(node);
 }

If we remove "extends": "airbnb" from our eslintConfig then the lint runs successfully (albeit with hundreds of linting errors, of course.)

@hzoo
Copy link
Member

hzoo commented Jan 30, 2016

Are you getting this issue with 5.0.0-beta6? (I just want to know if this to due to the beta7 changes)

@aweary
Copy link
Author

aweary commented Jan 30, 2016

Going back to 5.0.0-beta6 didn't resolve the issue, but regressing the acorn-to-esprima dependency to 2.0.6 resolves this issue.

@hzoo
Copy link
Member

hzoo commented Jan 30, 2016

Ah yeah beta7 was an acorn-to-esprima update so that must be the issue. cc @jmm it looks like the directive change caused this issue since this rule is checking all literals..

https://github.com/eslint/eslint/blob/master/lib/rules/no-irregular-whitespace.js#L124
https://github.com/eslint/eslint/blob/master/lib/rules/no-irregular-whitespace.js#L51

https://github.com/babel/acorn-to-esprima/pull/5/files

Just gotta add the node.raw value to literal since you changed it - code is above that

if (!node.raw) {
        if (node.extra && node.extra.raw) {
          node.raw = node.extra.raw;
        } else {
          node.raw = source.slice(node.start, node.end);
        }
      }

@jmm
Copy link
Member

jmm commented Jan 30, 2016

@hzoo Thanks for the links, I'll have to take a look. I'm not sure off the top of my head what would cause the difference from if Espree parsed the code to it's directive representation (which would have Literals). And I think the Babel produced nodes have raw.

@hzoo hzoo closed this as completed in ac4d3f0 Jan 30, 2016
@hzoo
Copy link
Member

hzoo commented Jan 30, 2016

Should be good on beta8

@jmm
Copy link
Member

jmm commented Jan 30, 2016

Thanks @hzoo!

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

No branches or pull requests

3 participants