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"
}
}]
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.
As JSON is based on a very restricted subset of JavaScript syntax, trailing commas are not allowed in JSON.
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With