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

Rule trailing-comma: TypeError: Cannot read property 'end' of undefined #4151

Closed
jiripospisil opened this issue Sep 4, 2018 · 4 comments
Closed

Comments

@jiripospisil
Copy link

Bug Report

  • TSLint version: 5.11.0
  • TypeScript version: 3.0.3
  • Running TSLint via: CLI or VSCode

TypeScript code being linted

class Foo {
  bar() {
    const params = {
      {}
    };

    if (true === true) {
    }
  }
}

with tslint.json configuration:

{
  "defaultSeverity": "error",
  "extends": [
    "tslint:recommended"
  ]
}

Actual behavior

tslint -c tslint.json kk.ts
The 'trailing-comma' rule threw an error in 'kk.ts':
TypeError: Cannot read property 'end' of undefined
    at cb (/private/tmp/tp-20180904190451/node_modules/.registry.npmjs.org/tslint/5.11.0/node_modules/tslint/lib/rules/trailingCommaRule.js:163:133)
    at visitNodes (/private/tmp/tp-20180904190451/node_modules/.registry.npmjs.org/typescript/3.0.3/node_modules/typescript/lib/typescript.js:15129:30)
    at Object.forEachChild (/private/tmp/tp-20180904190451/node_modules/.registry.npmjs.org/typescript/3.0.3/node_modules/typescript/lib/typescript.js:15428:21)
    at cb (/private/tmp/tp-20180904190451/node_modules/.registry.npmjs.org/tslint/5.11.0/node_modules/tslint/lib/rules/trailingCommaRule.js:170:23)
    at visitNodes (/private/tmp/tp-20180904190451/node_modules/.registry.npmjs.org/typescript/3.0.3/node_modules/typescript/lib/typescript.js:15129:30)
    at Object.forEachChild (/private/tmp/tp-20180904190451/node_modules/.registry.npmjs.org/typescript/3.0.3/node_modules/typescript/lib/typescript.js:15355:24)
    at TrailingCommaWalker.walk (/private/tmp/tp-20180904190451/node_modules/.registry.npmjs.org/tslint/5.11.0/node_modules/tslint/lib/rules/trailingCommaRule.js:172:19)
    at Rule.AbstractRule.applyWithWalker (/private/tmp/tp-20180904190451/node_modules/.registry.npmjs.org/tslint/5.11.0/node_modules/tslint/lib/language/rule/abstractRule.js:31:16)
    at Rule.apply (/private/tmp/tp-20180904190451/node_modules/.registry.npmjs.org/tslint/5.11.0/node_modules/tslint/lib/rules/trailingCommaRule.js:64:21)
    at Linter.applyRule (/private/tmp/tp-20180904190451/node_modules/.registry.npmjs.org/tslint/5.11.0/node_modules/tslint/lib/linter.js:197:29)
<snip>

Expected behavior

It should not crash.

@giladgray
Copy link

@jiripospisil to be fair, this is not valid javascript:

const params = {
    {}
};

image

@jiripospisil
Copy link
Author

@jiripospisil to be fair, this is not valid javascript:

@giladgray I'm aware but it's easy to get into a state which is not valid TS/JS while in the middle of changing code.

To be clear, I'm not running TSLint manually, I'm using VSCode and it runs it automatically via vscode-tslint.

image

I'm fairly certain there are other ways to trigger this because I've encountered it multiple times but the provided snippet seems pretty reliable and should be enough to add some sort of a fail-safe.

@thomaspink
Copy link

thomaspink commented Oct 30, 2018

Same issue, any updates on this one?

screenshot 2018-10-30 at 11 52 55

TypeError: Cannot read property 'end' of undefined
    at cb (/Users/thomas.pink/Development/angular-components/node_modules/tslint/lib/rules/trailingCommaRule.js:163:133)
    at visitNodes (/Users/thomas.pink/Development/angular-components/node_modules/typescript/lib/typescript.js:13272:30)
    at Object.forEachChild (/Users/thomas.pink/Development/angular-components/node_modules/typescript/lib/typescript.js:13421:24)
    at cb (/Users/thomas.pink/Development/angular-components/node_modules/tslint/lib/rules/trailingCommaRule.js:170:23)
    at visitNode (/Users/thomas.pink/Development/angular-components/node_modules/typescript/lib/typescript.js:13263:24)
    at Object.forEachChild (/Users/thomas.pink/Development/angular-components/node_modules/typescript/lib/typescript.js:13446:24)
    at cb (/Users/thomas.pink/Development/angular-components/node_modules/tslint/lib/rules/trailingCommaRule.js:170:23)
    at visitNode (/Users/thomas.pink/Development/angular-components/node_modules/typescript/lib/typescript.js:13263:24)
    at Object.forEachChild (/Users/thomas.pink/Development/angular-components/node_modules/typescript/lib/typescript.js:13457:24)
    at cb (/Users/thomas.pink/Development/angular-components/node_modules/tslint/lib/rules/trailingCommaRule.js:170:23)

@JoshuaKGoldberg
Copy link
Contributor

Duplicate of #3808

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

No branches or pull requests

4 participants