Is it possible to configure TSLint in Visual Studio 2015?
Asked Answered
T

4

14

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.

Triennial answered 1/6, 2016 at 17:52 Comment(3)
are you using gulp to transpile,test the ts code? did you have tslint.json in project root folder.Asshur
@Asshur No gulp. I have WebCompiler and TypeScript NuGet package installed.Triennial
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.Hays
M
13

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

Mysia answered 26/9, 2016 at 8:55 Comment(8)
I believe this should be the Accepted Answer to this questionTripersonal
Thank you, this helped me. Do you know if you can save a copy of the file in the solution?Priestley
@JonathanPeel, you can save a copy in the web project you are working on. Ensure that the file is saved as UTF-8 or you'll run into issues.Insatiate
Just for completion of this answer, Set: "quotemark": [true, "double"], to "quotemark": [true, "single"],Flume
On another note it's best to add a tslint.json file to the root project folder and change it there. Then the whole team uses the same configuration, once checked in to source control that is...Flume
I don't see a Tools>Web Code Analysis option. Am I missing something?Legatee
And I don't see tslint under Web Code AnalysisSchlesinger
I already have tslint.json in my project when I open this menu it shows something else not content of that file, what could be the issue?Horror
L
3

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.

Loquacity answered 8/7, 2016 at 11:13 Comment(1)
After more testing it was not the line endings but file encoding that was causing problems.Loquacity
F
2

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.

Fouquiertinville answered 19/5, 2017 at 19:51 Comment(0)
V
1

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.

Vankirk answered 6/6, 2016 at 3:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.