简体   繁体   English

是否可以在Visual Studio 2015中配置TSLint?

[英]Is it possible to configure TSLint in Visual Studio 2015?

TSLint is complaining that single-quotes should be double-quotes. TSLint抱怨单引号应该是双引号。 Our team prefers to use single-quotes to wrap string literals. 我们的团队更喜欢使用单引号来包装字符串文字。

I see that TSLint is configurable to set the mode to single-quote, but I cannot find a way to set these rules in Visual Studio 2015. 我看到TSLint可配置为将模式设置为单引号,但我找不到在Visual Studio 2015中设置这些规则的方法。

In Options, I found a couple of TSLint options under Text Editor > TypeScript > TSLint: 在Options中,我在Text Editor> TypeScript> TSLint下找到了几个TSLint选项:

  • Enable TSLint 启用TSLint
  • Warnings as errors 警告为错误

Obviously, these aren't the settings for which I'm looking... 显然,这些不是我正在寻找的设置......

Has anyone found a way to configure the TSLint rules in Visual Studio 2015, or is this something we just have to hope they add in the near future? 有没有人找到在Visual Studio 2015中配置TSLint规则的方法,或者这是我们不得不希望它们在不久的将来添加的东西?


This solution: Setup TSLint in Visual Studio 2015 此解决方案: 在Visual Studio 2015中设置TSLint

Seems to just be about adding TSLint to Visual Studio 2015 if it doesn't already exist. 似乎只是将TSLint添加到Visual Studio 2015(如果它尚不存在)。 That's not what I'm looking for either. 这不是我正在寻找的。

Tools > Web Code Analysis > Edit TSLint Settings (tslint.json)

Add tslint.json to your project root and configure it with that. 将tslint.json添加到项目根目录并使用它进行配置。 I had hard time to get this to work. 我很难让这个工作。 Seems that there is a bug somewhere and tslint.json only works when it has Windows line endings. 似乎某处存在错误,tslint.json仅在具有Windows行结尾时才起作用。 So make sure you have Windows line endings \\r\\n and not UNIX \\n. 因此,请确保您拥有Windows行结尾\\ r \\ n而不是UNIX \\ n。

Update: First I thought it was line endings that was causing this problem. 更新:首先我认为这是导致此问题的行结尾。 But it's actually tslint.json files encoding. 但它实际上是tslint.json文件编码。 If encoding is shown as UTF-8-BOM in Notepad++ the file refuses to work. 如果在Notepad ++中将编码显示为UTF-8-BOM,则文件拒绝工作。 If you change encoding to UTF-8 it starts to work. 如果您将编码更改为UTF-8,它将开始工作。

If you're still having problems, try upgrading to the latest version of TypeScript for Visual Studio 2015 before adding tslint.json to your project root. 如果您仍然遇到问题,请在将tslint.json添加到项目根目录之前尝试升级到最新版本的TypeScript for Visual Studio 2015

I looked at this in late 2016, with Wanton's approach of adding tslint.json to the project root, and for whatever reason I couldn't get it to work. 我在2016年末看了这个,有了Wanton将tslint.json添加到项目根目录的方法,无论出于什么原因我都无法让它工作。 Possibly because I was using tslint-microsoft-contrib for some rules. 可能是因为我使用tslint-microsoft-contrib来制定一些规则。 Wanton's advice around UTF encoding and line endings did not help. Wanton关于UTF编码和行结尾的建议没有帮助。 Upgrading to the April 2017 version of TypeScript for Visual Studio seemed to fix it. 升级到2017年4月版的TypeScript for Visual Studio似乎解决了这个问题。

That said, I could always get it working using the Tools > Web Code Analysis > Edit TSLint Settings (tslint.json) option from Clark, but that's not ideal for me, because it's a machine-level setting, not a project-level setting. 也就是说,我总是可以使用Clark的Tools > Web Code Analysis > Edit TSLint Settings (tslint.json)选项来实现它,但这对我来说并不理想,因为它是机器级设置,而不是项目级设置。 Still, this may be a good enough solution for you. 不过,这对您来说可能是一个很好的解决方案。

Another variable to check is the settings at Tools -> Options -> External Web Tools . 另一个要检查的变量是Tools -> Options -> External Web Tools You may need to place .\\node_modules\\.bin higher than $(VSINSTALLDIR)\\Web\\External , depending on how you are using tslint. 您可能需要将.\\node_modules\\.bin高于$(VSINSTALLDIR)\\Web\\External ,具体取决于您使用tslint的方式。

If you're using tslint in Visual Studio using Web Analyzer then it looks like you can edit the tslint.json configuration file directly from the Web Analyzer's Tools menu. 如果您在使用Web Analyzer的 Visual Studio中使用tslint ,则看起来您可以直接从Web Analyzer的“工具”菜单编辑tslint.json配置文件。

Look at the above link in the Configuration section for the "Edit TSLint settings (tslint.json)" option. 查看“编辑TSLint设置(tslint.json)”选项的“配置”部分中的上述链接。

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

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