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

Make TSLint follow my rules in JS files

我在 Visual Studio 代码中使用 TSLint(通过 TSLint 扩展),它非常适合 .ts 文件。它还在 .js 文件上运行,这很好,但它不使用相同的规则,这很糟糕(对我来说)。我怎样才能让它使用相同的规则?

我的 tslint.json 看起来像这样:

{
  "extends": "tslint:latest",
  "rules": {
    "indent": [true, "tabs"],
    // a bunch of others
  }
}

例如,我在 .js 文件中收到此警告:

[tslint] space indentation expected (indent)

(当我的规则设置为 "tabs" 时,它要我使用 space 缩进。)

您可以通过 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,您将禁用或覆盖不需要的规则。