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

Created on 4 Sep 2018  路  4Comments  路  Source: palantir/tslint

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.

Duplicate Bug

Most helpful comment

@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.

All 4 comments

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

const params = {
    {}
};

image

@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.

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)

Duplicate of #3808

Was this page helpful?
0 / 5 - 0 ratings