Set up TSLint for VS2017
Asked Answered
S

4

10

I have tried to install this plugin: Web Analyzer, but unfortunately it can not be installed in VS 2017. It showed:

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

I am wondering whether there is a way to set up tslint in VS or there is any other way to check the syntax?

Susurrate answered 16/3, 2017 at 3:24 Comment(0)
F
6

Now that TypeScript has language server plugins support and there's TSLint plugin, another option is available:

  • Install Visual Studio 2017 Update 2
  • Install TypeScript 2.3 for Visual Studio (This is not only for VS 2015 but also for VS 2017 Update 2)
  • Put tslint.json in C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.3 or any of its parent directories and run npm install typescript tslint tslint-language-service (Visual Studio doesn't search for tslint.json or plugins in the project folder)
  • Add "plugins": [{ "name": "tslint-language-service" }] to compilerOptions in your tsconfig.json

Now TSLint in Visual Studio should work:

enter image description here

Fondue answered 7/5, 2017 at 13:1 Comment(4)
Has anyone managed to get this to work with the latest versions of TypeScript and the language service? The link above now installs intellisense for TypeScript 2.4, but then I follow the steps above and don't get any linting.Persson
I followed the instructions and get no changes, can you please give more details about this? (your tsconfig.json for example). Thanks a lotRecoil
See my answer below for and updated version of this that works with TypeScript 3+Nickinickie
This answer is no longer working for TS 3+, I suggest using @Nickinickie answer.Stanza
N
7

Since this is the top google result, I wanted to add a more recent answer. Microsoft has a tslint plugin now that works with Typescript 3+ and across Visual Studio, VSCode and other editors:

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

Setup

Install Dependencies

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

Add to tsconfig.json:

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

Develop with lint!

Nickinickie answered 3/5, 2019 at 13:59 Comment(1)
Just a quick note that after running the install and updating your config file, remember to restart your editor. Reloading the solution alone won't do it.Therapist
F
6

Now that TypeScript has language server plugins support and there's TSLint plugin, another option is available:

  • Install Visual Studio 2017 Update 2
  • Install TypeScript 2.3 for Visual Studio (This is not only for VS 2015 but also for VS 2017 Update 2)
  • Put tslint.json in C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.3 or any of its parent directories and run npm install typescript tslint tslint-language-service (Visual Studio doesn't search for tslint.json or plugins in the project folder)
  • Add "plugins": [{ "name": "tslint-language-service" }] to compilerOptions in your tsconfig.json

Now TSLint in Visual Studio should work:

enter image description here

Fondue answered 7/5, 2017 at 13:1 Comment(4)
Has anyone managed to get this to work with the latest versions of TypeScript and the language service? The link above now installs intellisense for TypeScript 2.4, but then I follow the steps above and don't get any linting.Persson
I followed the instructions and get no changes, can you please give more details about this? (your tsconfig.json for example). Thanks a lotRecoil
See my answer below for and updated version of this that works with TypeScript 3+Nickinickie
This answer is no longer working for TS 3+, I suggest using @Nickinickie answer.Stanza
U
3

Web Analyser is there installed as part of Visual Studio 2017. The bad news: without tslint.

I suspect (was hoping) that it can be done using the taskrunner and gulp and piping the output back into the Visual Studio 2017 errors window (using the 'msbuild' output of tslint), but when I tried this I couldn't get it to work, and I don't have the time to work it out why. It may be this output option is not supported in vs2017.

My solution was to roll back to vs2015 community. (I also got back the code lens feature which I had grown to depend on.) I'm hoping that these things will come back to vs eventually, so I can move forward to some of the new features.

UPDATE: Rich Newman has written a replacement called TypeScript Analyzerfor vs2017 https://marketplace.visualstudio.com/items?itemName=RichNewman.TypeScriptAnalyzer

Unwholesome answered 18/4, 2017 at 0:56 Comment(1)
UPDATE: These issue have gone away for me in VS2019.Unwholesome
A
3

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

Aunt answered 2/5, 2017 at 12:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.