我在Visual Studio Code中使用TSLint(通过TSLint扩展),它对.ts
文件非常有用。它也运行在.js
文件上,这很好,但它不使用相同的规则,这对我来说是不好的。如何让它使用相同的规则?
我的tslint.json
看起来像这样:
{
"extends": "tslint:latest",
"rules": {
"indent": [true, "tabs"],
// a bunch of others
}
}
例如,我在.js
文件中收到此警告:
[tslint] space indentation expected (indent)
(当我的规则设置为"tabs"
时,它希望我使用空格缩进。)
答案 0 :(得分:6)
您可以通过tslint.json
file中的jsRules
属性指定要在JS文件上运行的规则。例如:
{
"extends": "tslint:latest",
"rules": {
"indent": [true, "tabs"],
// a bunch of others
},
"jsRules": {
"indent": [true, "tabs"],
// a bunch more rules
}
}
如果您在撰写本文时延长了tslint:latest
,these are the default rules,那么您将禁用或覆盖您不想要的规则。