typescript tslint - 最后一行缺少尾随逗号(尾随逗号)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52218260/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
tslint - Missing trailing comma (trailing-comma) on the last line
提问by Max Travis
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.
我不明白为什么我tslint
什至想在objects
? 例如,如何ignore
为对象的最后一行设置规则?谢谢。
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
在我的规则tsconfig.json
:
"trailing-comma": [true, {
"singleline": "never",
"multiline": {
"objects": "always",
"arrays": "always",
"functions": "never",
"typeLiterals": "ignore"
}
}]
回答by T.J. Crowder
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).
所以...通过设置禁用它"never"
(如果你想在那里禁止逗号)或"ignore"
(如果你想允许逗号在那里,无论哪种方式)。
回答by M.Liscio
I solved this in my tslint.json
as following:
我在我tslint.json
的如下解决了这个问题:
"rules": { "trailing-comma": false }