tslint - Missing trailing comma (trailing-comma) on the last line

Viewed 29992

I cannot figure out why my tslint even want to see the trailing comma on the end of the last line in the objects? How can I set the ignore rule for the last line of the objects for example? Thanks.

Exemple:

  props = {
    prop1: 21, // good
    prop2: 2, // good
    prop3: false // error: [tslint] Missing trailing comma (trailing-comma)

  }

Rule for trailing-comma in my tsconfig.json:

"trailing-comma": [true, {
  "singleline": "never",
  "multiline": {
    "objects": "always",
    "arrays": "always",
    "functions": "never",
    "typeLiterals": "ignore"
  }
}]
3 Answers

You clearly have the rule enabled for multi-line objects:

"trailing-comma": [true, {
  "singleline": "never",
  "multiline": {
    "objects": "always",     // <==================
    "arrays": "always",
    "functions": "never",
    "typeLiterals": "ignore"
  }
}]

So...disable it by making that "never" (if you want to disallow commas there) or "ignore" (if you want to allow commas to be there or not, either way).

Include trailing comma even in the last line is a good practice of having less merge conflict, although it looks weird.

I solved this in my tslint.json as following:

"rules": { "trailing-comma": false }
Related