Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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"
  }
}]
like image 462
Max Travis Avatar asked Sep 07 '18 08:09

Max Travis


People also ask

What is a trailing comma?

A trailing comma, also known as a dangling or terminal comma, is a comma symbol that is typed after the last item of a list of elements. Since the introduction of the JavaScript language, trailing commas have been legal in array literals. Later, object literals joined arrays.

Does JSON allow trailing commas?

As JSON is based on a very restricted subset of JavaScript syntax, trailing commas are not allowed in JSON.

What is trailing comma in Python?

Description: In Python, a tuple is actually created by the comma symbol, not by the parentheses. Unfortunately, one can actually create a tuple by misplacing a trailing comma, which can lead to potential weird bugs in your code.


1 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).

like image 66
T.J. Crowder Avatar answered Sep 16 '22 21:09

T.J. Crowder