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

trailing-comma throws TypeError on incomplete "function" declaration #4456

Closed
steinuil opened this issue Jan 11, 2019 · 1 comment
Closed

Comments

@steinuil
Copy link
Contributor

Bug Report

  • TSLint version: 5.12.1
  • TypeScript version: 3.2.2
  • Running TSLint via: CLI / Visual Studio

TypeScript code being linted

function

with tslint.json configuration:

{
  "extends": "tslint:latest"
}

Actual behavior

Throws an error:

[Warn  - 12:31:41 PM] The 'trailing-comma' rule threw an error in '[...]/test.ts':
TypeError: Cannot read property 'end' of undefined
    at cb ([...]\node_modules\tslint\lib\rules\trailingCommaRule.js:169:133)
    at visitNodes ([...]\node_modules\typescript\lib\typescript.js:16144:30)
    at Object.forEachChild ([...]\node_modules\typescript\lib\typescript.js:16372:24)
    at TrailingCommaWalker.walk ([...]\node_modules\tslint\lib\rules\trailingCommaRule.js:178:19)
    at Rule.AbstractRule.applyWithWalker ([...]\node_modules\tslint\lib\language\rule\abstractRule.js:31:16)
    at Rule.apply ([...]\node_modules\tslint\lib\rules\trailingCommaRule.js:68:21)
    at Linter.applyRule ([...]\node_modules\tslint\lib\linter.js:209:29)
    at [...]\node_modules\tslint\lib\linter.js:150:85
    at Object.flatMap ([...]\node_modules\tslint\lib\utils.js:160:29)
    at Linter.getAllFailures ([...]\node_modules\tslint\lib\linter.js:150:32)

Expected behavior

The output log is not trashed every time I write function in VS Code.

The offending piece of code in trailingCommaRule.ts uses a non-null type assertion, would it be ok to just wrap that call in a conditional?

@JoshuaKGoldberg
Copy link
Contributor

would it be ok to just wrap that call in a conditional?

Yes please!

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

2 participants