Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Cannot read property 'range' of undefined #156

Closed
mattdell opened this issue Feb 10, 2017 · 6 comments
Closed

Cannot read property 'range' of undefined #156

mattdell opened this issue Feb 10, 2017 · 6 comments
Labels

Comments

@mattdell
Copy link

What version of TypeScript are you using?
2.1.5

What version of typescript-eslint-parser are you using?
1.0.2

What code were you trying to parse?
All of my code. I've switched from babel-parser to typescript-eslint-parser. The most useful thing I can provide might be my .eslintrc file.

parser: typescript-eslint-parser

extends: airbnb

plugins: [react, jsx-a11y, import, extra-rules]

parserOptions:
  sourceType: module

ecmaFeatures:
  jsx: true

env:
  es6: true
  browser: true
  node: true
  mocha: true

globals:
  __DEV__: false
  __TEST__: false
  __PROD__: false
  __COVERAGE__: false
  sinon: false
  expect: false

settings:
  import/parsers:
    typescript-eslint-parser: [ .ts, .tsx ]

rules:
  # Disabled rules we should enable
  react/no-find-dom-node: 0
  react/no-string-refs: 0

  #Disabled
  react/jsx-no-bind: 0
  react/jsx-filename-extension: 0
  react/forbid-prop-types: 0
  react/prefer-stateless-function: 0
  max-len: 0
  no-underscore-dangle: 0
  class-methods-use-this: 0
  global-require: 0
  import/no-named-as-default: 0
  jsx-a11y/no-static-element-interactions: 0
  no-param-reassign: 0
  import/no-extraneous-dependencies: ["error", {"devDependencies": ["**/*.spec.js", "server/**/*.*"]}]

  # Errors
  object-shorthand: [2, properties]
  extra-rules/no-commented-out-code: 2
  jsx-quotes: ["error", "prefer-double"]
  space-before-function-paren: ["error", "never"]
  comma-dangle: ["error", "always-multiline"]

What did you expect to happen?
Lint my project!

What happened?
A horrible error.

Cannot read property 'range' of undefined
TypeError: Cannot read property 'range' of undefined
    at SourceCode.isSpaceBetweenTokens (/Users/mdell/Work/Repos/double-helix-web/node_modules/eslint/lib/util/source-code.js:296:43)
    at validateAfterOpening (/Users/mdell/Work/Repos/double-helix-web/node_modules/eslint-plugin-react/lib/rules/jsx-tag-spacing.js:139:30)
    at EventEmitter.JSXClosingElement (/Users/mdell/Work/Repos/double-helix-web/node_modules/eslint-plugin-react/lib/rules/jsx-tag-spacing.js:229:11)
    at emitOne (events.js:101:20)
    at EventEmitter.emit (events.js:188:7)
    at NodeEventGenerator.enterNode (/Users/mdell/Work/Repos/double-helix-web/node_modules/eslint/lib/util/node-event-generator.js:39:22)
    at CodePathAnalyzer.enterNode (/Users/mdell/Work/Repos/double-helix-web/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:607:23)
    at CommentEventGenerator.enterNode (/Users/mdell/Work/Repos/double-helix-web/node_modules/eslint/lib/util/comment-event-generator.js:98:23)
    at Controller.enter (/Users/mdell/Work/Repos/double-helix-web/node_modules/eslint/lib/eslint.js:928:36)
    at Controller.__execute (/Users/mdell/Work/Repos/double-helix-web/node_modules/estraverse/estraverse.js:397:31)

I'm not really sure where to even start with this one.

@soda0289
Copy link
Member

Looks like you might have some JSX in your code. We have some issues parsing that at the moment. Check out this issue:
#70

If you can lint one source file at a time that could help narrow it down.

@mattdell
Copy link
Author

Ah yes, this is a JSX heavy project. I can confirm this does work if I run it against a .ts file without any JSX.

Seems very related to #70 then.

@JamesHenry
Copy link
Member

Please provide minimal source code which will trigger this issue, or close if it is also the JSX text issue.

I am definitely keen to get these JSX issues worked out as soon as we can, but it's important we are clear on what the different problems are.

@mattdell
Copy link
Author

Sorry for the delay, but here's a very simple example I have:

import React from 'react';

export default () => (
  <div>
    <h1>A simple header</h1>
  </div>
);

Results in

Cannot read property 'range' of undefined
TypeError: Cannot read property 'range' of undefined
    at SourceCode.isSpaceBetweenTokens (/Users/mdell/Work/Repos/my-project/web/node_modules/eslint/lib/util/source-code.js:296:43)
    at validateAfterOpening (/Users/mdell/Work/Repos/my-project/web/node_modules/eslint-plugin-react/lib/rules/jsx-tag-spacing.js:139:30)
    at EventEmitter.JSXClosingElement (/Users/mdell/Work/Repos/my-project/web/node_modules/eslint-plugin-react/lib/rules/jsx-tag-spacing.js:229:11)
    at emitOne (events.js:101:20)
    at EventEmitter.emit (events.js:188:7)
    at NodeEventGenerator.enterNode (/Users/mdell/Work/Repos/my-project/web/node_modules/eslint/lib/util/node-event-generator.js:39:22)
    at CodePathAnalyzer.enterNode (/Users/mdell/Work/Repos/my-project/web/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:607:23)
    at CommentEventGenerator.enterNode (/Users/mdell/Work/Repos/my-project/web/node_modules/eslint/lib/util/comment-event-generator.js:98:23)
    at Controller.enter (/Users/mdell/Work/Repos/my-project/web/node_modules/eslint/lib/eslint.js:928:36)
    at Controller.__execute (/Users/mdell/Work/Repos/my-project/web/node_modules/estraverse/estraverse.js:397:31)

@soda0289
Copy link
Member

This will be fixed by #158

@JamesHenry
Copy link
Member

This should now be fixed on master, full release coming soon!

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

No branches or pull requests

4 participants