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

kind of undefined in canHaveLeadingTrivia #2330

Closed
Pajn opened this issue Mar 11, 2017 · 3 comments · Fixed by #2386 or singapore/lint-condo#263
Closed

kind of undefined in canHaveLeadingTrivia #2330

Pajn opened this issue Mar 11, 2017 · 3 comments · Fixed by #2386 or singapore/lint-condo#263

Comments

@Pajn
Copy link
Contributor

Pajn commented Mar 11, 2017

Bug Report

  • TSLint version: 4.5.1
  • TypeScript version: 2.2.1
  • Running TSLint via: (pick one) VSCode

TypeScript code being linted

No minimal case, but I don't think it's needed here.

Actual behavior

TypeError: Cannot read property 'kind' of undefined
    at canHaveLeadingTrivia (/home/rasmus/Development/control-flow/ts/node_modules/tsutils/src/utils.js:309:26)
    at /home/rasmus/Development/control-flow/ts/node_modules/tsutils/src/utils.js:283:23
    at iterate (/home/rasmus/Development/control-flow/ts/node_modules/tsutils/src/utils.js:251:20)
    at Array.forEach (native)
    at iterate (/home/rasmus/Development/control-flow/ts/node_modules/tsutils/src/utils.js:253:50)
    at Array.forEach (native)
    at iterate (/home/rasmus/Development/control-flow/ts/node_modules/tsutils/src/utils.js:253:50)
    at forEachToken (/home/rasmus/Development/control-flow/ts/node_modules/tsutils/src/utils.js:254:7)
    at Object.forEachComment (/home/rasmus/Development/control-flow/ts/node_modules/tsutils/src/utils.js:282:12)
    at EnableDisableRulesWalker.getEnableDisableRuleMap (/home/rasmus/Development/control-flow/ts/node_modules/tslint/lib/enableDisableRules.js:42:15)

The line if (parent.parent.kind === ts.SyntaxKind.JsxClosingElement) in canHaveLeadingTrivia must guard for the node not having grandparents, something like if (parent.parent && parent.parent.kind === ts.SyntaxKind.JsxClosingElement)

ajafff added a commit to ajafff/tsutils that referenced this issue Mar 12, 2017
Remove erronous parent access.
Fixes: palantir/tslint#2330
@ajafff
Copy link
Contributor

ajafff commented Mar 12, 2017

parent.parent.kind was actually a bug and should have been parent.kind.
I just released [email protected] which includes this fix.

I couldn't reproduce the error. Can you share a code snipped that could be used as a regression test?

@Pajn
Copy link
Contributor Author

Pajn commented Mar 12, 2017

Great!

Can you share a code snipped that could be used as a regression test?

Sorry, I saw it in the logs in a larger project with format on save when I tried to investigated why format all (and therefore format on save) rarely works however I don't get it now. I might be able to reproduce it by jumping to older commits if there is some way I can see in at least which file it occurred?

EDIT: Now I managed to reproduce it by a syntax error, that might have been it thanks to the combination of format on save and save on focus change and looking up some docs while coding.
That even makes more sense as I sometimes have the original trouble of fix all not working even when I don't see the error in the logs (and no other error either, hmm... noticing a problem and seeing an exception in the log felt so connected).

If you are interested even in a syntax error reproduction, here it is:

const a =
  <span /
  >
  </span>

@ajafff
Copy link
Contributor

ajafff commented Mar 13, 2017

That's exactly what I was looking for.
While we cannot guarantee useful results from linting invalid source code, we at least try not to crash.

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

Successfully merging a pull request may close this issue.

2 participants