为 VS2017 设置 TSLint

Set up TSLint for VS2017

我试过安装这个插件:Web Analyzer,可惜在VS 2017中无法安装。它显示:

VSIXInstaller.NoApplicableSKUsException: This extension is not installable on any currently installed products.

我想知道是否有办法在 VS 中设置 tslint 或者有任何其他方法来检查语法?

Web Analyzer 作为 Visual Studio 2017 的一部分安装。坏消息:没有 tslint。

我怀疑(希望)可以使用 taskrunner 和 gulp 并将输出传送回 Visual Studio 2017 错误 window(使用 'msbuild' tslint 的输出),但是当我尝试这个时,我无法让它工作,而且我没有时间弄清楚为什么。可能是vs2017不支持这个输出选项。

我的解决方案是回滚到 vs2015 社区。 (我还找回了我一直依赖的代码镜头功能。)我希望这些东西最终会回到 vs 中,这样我就可以继续使用一些新功能。

更新: Rich Newman 为 vs2017 编写了一个名为 TypeScript Analyzer 的替代品 https://marketplace.visualstudio.com/items?itemName=RichNewman.TypeScriptAnalyzer

感谢Rich N, now there is TypeScript Analyzer for Visual Studio 2017. See his answer to an SO question on the same topic

现在 TypeScript 有 language server plugins support and there's TSLint plugin,另一个选项可用:

  • 安装Visual Studio 2017 Update 2
  • 安装TypeScript 2.3 for Visual Studio(这不仅适用于 VS 2015,也适用于 VS 2017 Update 2)
  • tslint.json 放入 C:\Program Files (x86)\Microsoft SDKs\TypeScript.3 或其任何父目录中,然后 运行 npm install typescript tslint tslint-language-service(Visual Studio 不搜索 tslint.json或项目文件夹中的插件)
  • 在您的 tsconfig.json
  • 中将 "plugins": [{ "name": "tslint-language-service" }] 添加到 compilerOptions

现在 Visual Studio 中的 TSLint 应该可以工作了:

由于这是最高 google 结果,我想添加一个更新的答案。微软现在有一个 tslint 插件,它可以与 Typescript 3+ 一起使用,并且适用于 Visual Studio、VSCode 和其他编辑器:

https://github.com/Microsoft/typescript-tslint-plugin

设置

安装依赖项

npm install --save-dev typescript tslint typescript-tslint-plugin

添加到tsconfig.json:

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "typescript-tslint-plugin"
      }
    ]
  }
}

使用 lint 进行开发!