14
votes

TSLint is complaining that single-quotes should be double-quotes. 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.

In Options, I found a couple of TSLint options under Text Editor > TypeScript > TSLint:

  • Enable 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?


This solution: Setup TSLint in Visual Studio 2015

Seems to just be about adding TSLint to Visual Studio 2015 if it doesn't already exist. That's not what I'm looking for either.

4
are you using gulp to transpile,test the ts code? did you have tslint.json in project root folder.Ajay
@Ajay No gulp. I have WebCompiler and TypeScript NuGet package installed.crush
Maybe the MSBuild task for tslint can help. I have not tried it but it says it can use tslint.json, and it should install from nuget.Jonas Kello

4 Answers

13
votes

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

3
votes

Add tslint.json to your project root and configure it with that. 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. So make sure you have Windows line endings \r\n and not UNIX \n.

Update: First I thought it was line endings that was causing this problem. But it's actually tslint.json files encoding. If encoding is shown as UTF-8-BOM in Notepad++ the file refuses to work. If you change encoding to UTF-8 it starts to work.

2
votes

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.

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. Possibly because I was using tslint-microsoft-contrib for some rules. Wanton's advice around UTF encoding and line endings did not help. Upgrading to the April 2017 version of TypeScript for Visual Studio seemed to fix it.

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. Still, this may be a good enough solution for you.

Another variable to check is the settings at 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.

1
votes

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.

Look at the above link in the Configuration section for the "Edit TSLint settings (tslint.json)" option.