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

TypeError: Cannot read property 'parent' of null #1061

Closed
jakereps opened this issue Feb 5, 2017 · 5 comments · Fixed by singapore/lint-condo#262
Closed

TypeError: Cannot read property 'parent' of null #1061

jakereps opened this issue Feb 5, 2017 · 5 comments · Fixed by singapore/lint-condo#262
Assignees

Comments

@jakereps
Copy link

jakereps commented Feb 5, 2017

After updating using eslint-config-airbnb's instructions running my tests result in the following error (manually pathed to leave out other pieces of the test stack).

tracelog

[19:36] q2studio (master *) $ ./node_modules/eslint/bin/eslint.js app config --ext .js,.jsx --config config/eslint.yaml 
Cannot read property 'parent' of null
TypeError: Cannot read property 'parent' of null
    at EventEmitter.JSXOpeningElement (/Users/jakereps/Developer/caporasolab/q2studio/node_modules/eslint-plugin-react/lib/rules/jsx-indent.js:237:27)
    at emitOne (events.js:101:20)
    at EventEmitter.emit (events.js:188:7)
    at NodeEventGenerator.enterNode (/Users/jakereps/Developer/caporasolab/q2studio/node_modules/eslint/lib/util/node-event-generator.js:39:22)
    at CodePathAnalyzer.enterNode (/Users/jakereps/Developer/caporasolab/q2studio/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:607:23)
    at CommentEventGenerator.enterNode (/Users/jakereps/Developer/caporasolab/q2studio/node_modules/eslint/lib/util/comment-event-generator.js:98:23)
    at Controller.enter (/Users/jakereps/Developer/caporasolab/q2studio/node_modules/eslint/lib/eslint.js:928:36)
    at Controller.__execute (/Users/jakereps/Developer/caporasolab/q2studio/node_modules/estraverse/estraverse.js:397:31)
    at Controller.traverse (/Users/jakereps/Developer/caporasolab/q2studio/node_modules/estraverse/estraverse.js:501:28)
    at Controller.Traverser.controller.traverse (/Users/jakereps/Developer/caporasolab/q2studio/node_modules/eslint/lib/util/traverser.js:36:33)

package.json

// from
"eslint": "^2.6.0",
"eslint-config-airbnb": "^6.2.0",
"eslint-plugin-react": "^4.2.3",
// to
"eslint": "^3.15.0",
"eslint-config-airbnb": "^14.0.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^3.0.2",
"eslint-plugin-react": "^6.9.0",

environment

[19:47] q2studio (master *) $ node -v
v7.2.0
[19:47] q2studio (master *) $ npm -v
3.10.9

I've had no luck searching for this issue, so resulted in submitting this issue. Any ideas? Dropping the --ext .js,.jsx works, but will only scan .js files.

@ljharb
Copy link
Member

ljharb commented Feb 5, 2017

This is unrelated, but you want to use an npm run-script, or ./node_modules/.bin/eslint, not hardcode the path to the JS file.

This looks like there's some kind of code you might be using that eslint-plugin-react's jsx-indent rule is crashing on. If you open up that file (/Users/jakereps/Developer/caporasolab/q2studio/node_modules/eslint-plugin-react/lib/rules/jsx-indent.js, and on line 236, add console.log(context.getFileName()), and you check the last filename eslint reports before crashing, could you share that file's code?

@jakereps
Copy link
Author

jakereps commented Feb 5, 2017

Oh for sure, just for this output I did the manual path. It was failing in the same manner using my npm t runs, which had unrelated output so I just ran it on its own.

That helped! Took a bit of playing around, but it turned out that having a multi-line ternary that didn't wrap each possibility on either side of the colon with parenthesis would fail. First one that was breaking it was this block, and once that was fixed it broke again once it got down to this block. All good now! Not sure if that is by design, as the previous version could handle it. If it is, this should be good to close, but otherwise I can rename it as a bug that ambiguous multiline ternary blocks break parsing.

Thanks @ljharb!

@ljharb
Copy link
Member

ljharb commented Feb 5, 2017

Those links now show the same block - if you could provide the code that broke, it's definitely a bug we should be able to fix.

@jakereps
Copy link
Author

jakereps commented Feb 5, 2017

Oops, got the second one updated.

@gorangajic
Copy link

maybe it can be helpful, for me it's throwing when using template string

<Route
    path="/dashboard"
    render={props => <Redirect to={`/?login&next=${props.location.pathname}`} />}
/>

iancmyers added a commit to iancmyers/eslint-plugin-react that referenced this issue Feb 17, 2017
Template strings are constructed differently from other tokens in
espree. Other tokens are created by the Token class and are thus
Token class objects. They look like this:

```
Token {
  type: 'String',
  value: '"bar"',
  start: 44,
  end: 49,
  loc:
   SourceLocation {
     start: Position { line: 4, column: 11 },
     end: Position { line: 4, column: 16 } },
  range: [ 44, 49 ] }
```

Template tokens, however, are constructed differently and end up as
plain JavaScript objects, which look like this:

```
{ type: 'Template',
  value: '`bar`',
  loc:
   { start: Position { line: 4, column: 11 },
     end: Position { line: 4, column: 16 } },
  range: [ 44, 49 ] }
```

See: [espree's token-translator.js](https://github.com/eslint/espree/blob/58f75be6b89d8904b6366ed368045cb02c4a4e33/lib/token-translator.js#L43)

As a result of this different construction, the `start` and `end`
properties are not present on the template token object. To correct this
I've changed to using the `range` property, which I infer to be more
proper given the method it is being passed into is called
`getNodeByRangeIndex`. I also think we can safely rely on `range` being
present on all token types.

Fixes jsx-eslint#1061
iancmyers added a commit to iancmyers/espree that referenced this issue Jun 19, 2017
While fixing an issue in `eslint-plugin-react`
(jsx-eslint/eslint-plugin-react#1061),
I noticed that template tokens differ from other tokens. A typical token
looks like this:

```
Token {
  type: 'String',
  value: '"bar"',
  start: 44,
  end: 49,
  loc:
   SourceLocation {
     start: Position { line: 4, column: 11 },
     end: Position { line: 4, column: 16 } },
  range: [ 44, 49 ] }
```

A template token looks like this:

```
{ type: 'Template',
  value: '`bar`',
  loc:
   { start: Position { line: 4, column: 11 },
     end: Position { line: 4, column: 16 } },
  range: [ 44, 49 ] }
```

I've not be able to figure out why templates are plain JavaScript
objects and not of the class type `Token` (aside from the fact that the
template tokens are constructed differently in the token translator.

This fix copies the `range` values into `start` and `end` properties on
the template tokens to make them adhere to the same structure as other
token objects.

Fixes eslint#319
iancmyers added a commit to iancmyers/espree that referenced this issue Jun 21, 2017
While fixing an issue in `eslint-plugin-react`
(jsx-eslint/eslint-plugin-react#1061),
I noticed that template tokens differ from other tokens. A typical token
looks like this:

```
Token {
  type: 'String',
  value: '"bar"',
  start: 44,
  end: 49,
  loc:
   SourceLocation {
     start: Position { line: 4, column: 11 },
     end: Position { line: 4, column: 16 } },
  range: [ 44, 49 ] }
```

A template token looks like this:

```
{ type: 'Template',
  value: '`bar`',
  loc:
   { start: Position { line: 4, column: 11 },
     end: Position { line: 4, column: 16 } },
  range: [ 44, 49 ] }
```

I've not be able to figure out why templates are plain JavaScript
objects and not of the class type `Token` (aside from the fact that the
template tokens are constructed differently in the token translator.

This fix copies the `range` values into `start` and `end` properties on
the template tokens to make them adhere to the same structure as other
token objects.

Fixes eslint#319
iancmyers added a commit to iancmyers/espree that referenced this issue Jun 21, 2017
While fixing an issue in `eslint-plugin-react`
(jsx-eslint/eslint-plugin-react#1061),
I noticed that template tokens differ from other tokens. A typical token
looks like this:

```
Token {
  type: 'String',
  value: '"bar"',
  start: 44,
  end: 49,
  loc:
   SourceLocation {
     start: Position { line: 4, column: 11 },
     end: Position { line: 4, column: 16 } },
  range: [ 44, 49 ] }
```

A template token looks like this:

```
{ type: 'Template',
  value: '`bar`',
  loc:
   { start: Position { line: 4, column: 11 },
     end: Position { line: 4, column: 16 } },
  range: [ 44, 49 ] }
```

I've not be able to figure out why templates are plain JavaScript
objects and not of the class type `Token` (aside from the fact that the
template tokens are constructed differently in the token translator.

This fix copies the `range` values into `start` and `end` properties on
the template tokens to make them adhere to the same structure as other
token objects.

Fixes eslint#319
not-an-aardvark pushed a commit to eslint/espree that referenced this issue Jul 10, 2017
While fixing an issue in `eslint-plugin-react`
(jsx-eslint/eslint-plugin-react#1061),
I noticed that template tokens differ from other tokens. A typical token
looks like this:

```
Token {
  type: 'String',
  value: '"bar"',
  start: 44,
  end: 49,
  loc:
   SourceLocation {
     start: Position { line: 4, column: 11 },
     end: Position { line: 4, column: 16 } },
  range: [ 44, 49 ] }
```

A template token looks like this:

```
{ type: 'Template',
  value: '`bar`',
  loc:
   { start: Position { line: 4, column: 11 },
     end: Position { line: 4, column: 16 } },
  range: [ 44, 49 ] }
```

I've not be able to figure out why templates are plain JavaScript
objects and not of the class type `Token` (aside from the fact that the
template tokens are constructed differently in the token translator.

This fix copies the `range` values into `start` and `end` properties on
the template tokens to make them adhere to the same structure as other
token objects.

Fixes #319
not-an-aardvark pushed a commit to eslint/espree that referenced this issue Jul 10, 2017
While fixing an issue in `eslint-plugin-react`
(jsx-eslint/eslint-plugin-react#1061),
I noticed that template tokens differ from other tokens. A typical token
looks like this:

```
Token {
  type: 'String',
  value: '"bar"',
  start: 44,
  end: 49,
  loc:
   SourceLocation {
     start: Position { line: 4, column: 11 },
     end: Position { line: 4, column: 16 } },
  range: [ 44, 49 ] }
```

A template token looks like this:

```
{ type: 'Template',
  value: '`bar`',
  loc:
   { start: Position { line: 4, column: 11 },
     end: Position { line: 4, column: 16 } },
  range: [ 44, 49 ] }
```

I've not be able to figure out why templates are plain JavaScript
objects and not of the class type `Token` (aside from the fact that the
template tokens are constructed differently in the token translator.

This fix copies the `range` values into `start` and `end` properties on
the template tokens to make them adhere to the same structure as other
token objects.

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

Successfully merging a pull request may close this issue.

4 participants