使TSLint遵循我在JS文件中的规则

时间:2016-12-30 14:14:19

标签: visual-studio-code tslint

我在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"时,它希望我使用空格缩进。)

1 个答案:

答案 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:latestthese are the default rules,那么您将禁用或覆盖您不想要的规则。