Tslint: Rule "trailing-comma" provides false positive on object rest in destructuring assignment

Created on 27 Mar 2018  路  5Comments  路  Source: palantir/tslint

Bug Report

  • __TSLint version__: 5.9.1
  • __TypeScript version__: 2.7.2
  • __Running TSLint via__: VSCode

TypeScript code being linted

const {
  onEnter,
  refField,
  meta,
  input: { onChange, ...remainingInputProps },
  ...remainingProps
} = this.props;

with tslint.json configuration:

{
  "extends": ["tslint:latest", "tslint-react"]
}

Actual behavior

Missing trailing comma (trailing-comma) error is raised on object rest.

Expected behavior

Missing trailing comma (trailing-comma) error should not be raised on object rest.

Most helpful comment

@aervin Perfect! That was exactly what I was after. Thank you for your help.

All 5 comments

@charles-salmon I think this is (or has been) a topic of discussion already.

@aervin Apologies, I missed that. It looks as though the last issue was closed on the basis that it is _valid_ to use a comma after an object rest in TypeScript, so perhaps it's not very fitting for this to have been raised as a Bug Report.

Stylistically, however, I'm now convinced that it makes little sense to enforce that an object rest _must have_ a comma. The point of the trailing-comma rule is to produce clean diffs. This enforcement has no impact on producing clean diffs, while it creates a difference from ES6 specification. Is this a discussion worth revisiting?

@charles-salmon I took a look at the docs and found this: To align this rule with the ECMAScript specification that is implemented in modern JavaScript VMs, there is a third option esSpecCompliant. Set this option to true to disallow trailing comma on object and array rest and rest parameters. Could this solve the problem? I've never tried it myself.

@aervin Perfect! That was exactly what I was after. Thank you for your help.

Since TypeScript now disallows commas after an object rest param, I submitted a followup: #4172.

Was this page helpful?
0 / 5 - 0 ratings