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

trailing-comma rule should not suggest comma after an object rest param in destructuring #4172

Closed
mgol opened this issue Sep 18, 2018 · 6 comments

Comments

@mgol
Copy link

mgol commented Sep 18, 2018

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.

@JoshuaKGoldberg
Copy link
Contributor

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

Should that be enabled by default?

@mgol
Copy link
Author

mgol commented Nov 5, 2018

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.

@adidahiya
Copy link
Contributor

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

@adidahiya adidahiya changed the title TSLint incorrectly requires a trailing comma after an object rest param in destructuring trailing-comma rule should not suggest comma after an object rest param in destructuring Jan 10, 2019
@adidahiya adidahiya added this to the TSLint 6.0 milestone Jan 10, 2019
@JoshuaKGoldberg
Copy link
Contributor

JoshuaKGoldberg commented Oct 2, 2019

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

@JoshuaKGoldberg
Copy link
Contributor

💀 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!

@JoshuaKGoldberg
Copy link
Contributor

🤖 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! 👋

@palantir palantir locked and limited conversation to collaborators Mar 20, 2020
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

3 participants