Tslint: trailing-comma rule should not suggest comma after an object rest param in destructuring

Created on 18 Sep 2018  ยท  6Comments  ยท  Source: palantir/tslint

Bug Report

  • __TSLint version__: 5.11.0 (also, what the Playground uses)
  • __TypeScript version__: 3.1.0-rc (also, what the Playground uses)
  • __Running TSLint via__: (pick one) Node.js & Playground

TypeScript code being linted

declare const o;

const {
    a,
    ...rest
} = o;

with tslint.json configuration:

{
    "rules": {
        "trailing-comma": [true, {"multiline": "always", "singleline": "never"}]
    }
}

See it on Playground.

Actual behavior

An error occurs, indicating a trailing comma is expected.

Expected behavior

Latest TypeScript disallows a trailing comma after an object rest param in destructuring to align with ECMAScript. This TSLint behavior requires to apply changes to the code that will make it not compile.

This was raised before in #3147 & #3795. However, then it was only a question of aligning with JavaScript and a style preference. Now it's an actual bug.

Breaking Change Bug ๐ŸŒน R.I.P. ๐ŸŒน

Most helpful comment

Adding "esSpecCompliant": true to the rule's options object fixes this.

Should that be enabled by default?

All 6 comments

Adding "esSpecCompliant": true to the rule's options object fixes this.

Should that be enabled by default?

Yes, I think so. That's how I work around it in my code but default settings shouldn't require invalid syntax.

TBH, barring the breaking changes issue, I think this option shouldn't even exist as it's no longer possible to be non-ES compliant anymore here. IIRC this option was added as some people wanted to write code in a syntax compatible with upstream ECMAScript. The TypeScript language tries to remain close to ES syntax, though, so eventually, this hole was closed.

Being able to set "esSpecCompliant": false is only relevant to users of older TypeScript versions.

esSpecCompliant: true is enabled in all the built-in configs, tslint:all, tslint:recommended, and tslint:latest, which I believe should be sufficient for most users. we can change the behavior of the rule to make esSpecCompliant: true the default behavior in v6.0

~Removing~ Ignoring the Type: Breaking Change label per #4811. Now accepting PRs!

๐Ÿ’€ _It's time!_ ๐Ÿ’€

TSLint is deprecated and no longer accepting pull requests other than security fixes. See #4534. โ˜ ๏ธ
We recommend you instead use typescript-eslint to lint your TypeScript code with ESLint. โœ…

๐Ÿ‘‹ It was a pleasure open sourcing with you!

๐Ÿค– Beep boop! ๐Ÿ‘‰ TSLint is deprecated ๐Ÿ‘ˆ _(#4534)_ and you should switch to typescript-eslint! ๐Ÿค–

๐Ÿ”’ This issue is being locked to prevent further unnecessary discussions. Thank you! ๐Ÿ‘‹

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cateyes99 picture cateyes99  ยท  3Comments

adidahiya picture adidahiya  ยท  3Comments

ghost picture ghost  ยท  3Comments

denkomanceski picture denkomanceski  ยท  3Comments

allbto picture allbto  ยท  3Comments