Tslint: trailing-comma false positive

Created on 2 Mar 2017  路  5Comments  路  Source: palantir/tslint

Bug Report

  • __TSLint version__: 4.5.0
  • __TypeScript version__: 2.2.1
  • __Running TSLint via__: (pick one) CLI, VSCode

TypeScript code being linted

interface A {
    b: {
        c: string // ok
        d: string // [tslint] Missing trailing comma (trailing-comma)
    }
    e: string // ok
}

with tslint.json configuration:

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

Actual behavior

Requires comma at last nested type member

Expected behavior

Should not

Duplicate

Most helpful comment

Ah, sorry I think I misread the first code snippet. This looks like a duplicate of #1810.

All 5 comments

That's the same problem we also have with interfaces #1810. Members can end with comma, semicolon or just a line break.
Instead of finding a smart solution to guess if a trailing comma is desired, we should add config options for those cases (and maybe even more options for other cases #2286)

I recently refactored this rule in #2236. The PR is not merged yet so I could add the new options while I'm already touching the code.

Why would you _not_ want trailing commas on interfaces with "multiline": "always"? Can you provide a convincing argument that the rule needs to be customizable in that way? There's even an auto-fixer; this should be trivial to fix in your codebase.

This particular rule is about a trailing comma only, not about all separating commas. And I think it should not interfere with other style decisions, like omitting optional semicolons and commas whenever possible.

Ah, sorry I think I misread the first code snippet. This looks like a duplicate of #1810.

duplicate of #1810

In that case, closing.

Was this page helpful?
0 / 5 - 0 ratings