简体   繁体   English

在Visual Studio 2015/2017中使用TSLint吗?

[英]TSLint in Visual Studio 2015/2017?

My organization uses TSLint pretty heavily for quality-checking our Typescript code, and it provides a valuable service to us! 我的组织大量使用TSLint来质量检查我们的Typescript代码,它为我们提供了宝贵的服务! However, we use Visual Studio 2015 & 2017 as our main IDE and the only way to get the linting results it to run a gulp/grunt task which prints the output to the Task Runner Explorer console. 但是,我们将Visual Studio 2015和2017用作主要IDE,并且是获取毛刺结果的唯一方法,它可以运行gulp / grunt任务,该任务会将输出打印到Task Runner Explorer控制台。 It works, but it's slow and not the best development experience. 它可以工作,但是速度很慢,而不是最佳的开发体验。

In smaller projects on my own I've used VSCode, which has a fantastic TSLint plugin that highlights linting violations as you make them, and provides access to the auto-fixers that some TSLint rules have. 在我自己的较小项目中,我使用了VSCode,它具有一个出色的TSLint插件 ,可在您制作棉线违规时突出显示它们,并提供对某些TSLint规则所具有的自动修复程序的访问权限。 Like this: 像这样:

VSCode TSLint示例

Is it possible to get this same functionality in Visual Studio 2015/2017? 是否可以在Visual Studio 2015/2017中获得相同的功能? The immediate feedback is a life saver when writing TypeScript code. 在编写TypeScript代码时,即时反馈可以节省生命。

As @Hermann Gruber has mentioned, in Visual Studio 2015 Mads Kristensen's Web Analyzer extension provides support for TSLint of the kind you require. 正如@Hermann Gruber提到的那样,在Visual Studio 2015中, Mads Kristensen的Web分析器扩展为您需要的TSLint提供支持。

For Visual Studio 2017 and 2019 I have now personally upgraded Mads' extension, and rebranded it as 'TypeScript Analyzer' as it only supports TSLint. 对于Visual Studio 2017和2019,我现在已经亲自升级了Mads'扩展名,并将其更名为``TypeScript Analyzer'',因为它仅支持TSLint。 It's available in Visual Studio's Extensions and Updates Gallery under 'TypeScript Analyzer'. 它可以在Visual Studio的“扩展和更新库”中的“ TypeScript分析器”下找到。

This is something I coded in a day or two (note that I haven't worked with C# for a few years): 这是我在一两天内编写的代码(请注意,几年来我一直没有使用C#):

https://github.com/vladeck/TSLint https://github.com/vladeck/TSLint

It is a start of (hopefully) worth-wile Visual Studio 2017 extension that can mark .ts code withing the editor, based on the installed tslint and tslint.json configuration. 这是(希望如此)有价值的Visual Studio 2017扩展的开始,该扩展可以基于已安装的tslinttslint.json配置,使用编辑器标记.ts代码。

It is not published on the marketplace yet (a lot more coding to do), but you can download and build it yourself. 它尚未在市场上发布(还有很多代码要做),但是您可以自己下载并构建它。 Give it a try, If you have the time. 如果有时间,请尝试一下。 The more people try it out, the more I will have data needed to make it worth-wile. 尝试的人越多,我将需要更多的数据来使其变得有价值。

This is reported as an issue in the Visual Studio Developer Community. 在Visual Studio开发人员社区中,这被报告为问题。 https://developercommunity.visualstudio.com/content/problem/22907/please-support-tslint-as-how-its-supported-in-vs-c.html https://developercommunity.visualstudio.com/content/problem/22907/please-support-tslint-as-how-its-supported-in-vs-c.html

The status is "triaged", so I assume that a comparable feature is not (yet) available. 状态为“已分类”,因此我假设(尚未)提供类似功能。 You may want to upvote the issue, so that it gets more attention by the VS development team. 您可能需要对此问题进行投票,以便VS开发团队更加关注它。

EDIT: As noted in the following question, the visual studio plugin web analyzer provides support for tslint in VS 2015 (but not VS 2017): 编辑:如以下问题所述,Visual Studio插件Web分析器在VS 2015中提供了对tslint的支持(但不提供VS 2017):

Set up TSLint for VS2017 为VS2017设置TSLint

Looks like if you are using typescript 3.0 or higher you just need to add tslint plugin into your tsconfig file. 看起来,如果您使用的是Typescript 3.0或更高版本,则只需将tslint插件添加到tsconfig文件中。 Install typescript-tslint-plugin below and you may need to restart visual studio (or simply close all your files and re-open them) 在下面安装typescript-tslint-plugin ,您可能需要重新启动Visual Studio(或简单地关闭所有文件并重新打开它们)

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

First 第一

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

Then 然后

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM