45

I have installed TSLint in VSCode and created a tslint.json file next to tsconfig.json. But TSLint is not working. For example, I added "curly": true to tslint.json, but when I write a if statement without curly braces, VS Code doesn't give any warning. What does this extension do?

enter image description here

Zen
  • 5,065
  • 8
  • 29
  • 49
  • 11
    I was surprised to see the extension repo has absolutely zero info about what to expect after you install it. So far I've installed it and it is completely invisible. So I'm in the same boat as you. (And yes, I did restart vs code). – Charlie Flowers May 26 '16 at 20:47
  • 3
    Maybe your `tslint.json` is invalid. You can try cloning [this project](https://github.com/mrf28/a2gtm) and open it with vscode to see if tslint is working. @CharlieFlowers – Zen May 27 '16 at 01:15

7 Answers7

24

On a new machine, I installed VS Code tslint extension before installing tslint itself (via npm), and nothing helped to make it work other than disabling and re-enabling the extension.

enter image description here

V.B.
  • 6,236
  • 1
  • 33
  • 56
10

The vscode-tslint extension currently crashes silently when it encounters an invalid config-option. In my case, it was the no-trailing-comma rule which has to be changed to trailing-comma.

More info here: https://github.com/Microsoft/vscode-tslint/issues/66

opus131
  • 1,976
  • 1
  • 11
  • 13
  • 1
    Running tslint from commandline with a command similar to `tslint -c tslint.json 'src/**/*.ts'` should surface these errors as a workaround to the extension supporting this better – Thymine Jul 23 '18 at 23:08
  • In your `.vscode` directory, there may be a settings.json which could be overwriting your global vscode configuration `settings.json` ` { "typescript.tsdk": "./node_modules/typescript/lib", "tslint.configFile": "./src/code/tslint.json" } ` – TheBigFriezy Mar 14 '19 at 21:07
8

VS Code doesn't give any warning. What does this extension do

When in doubt. Restart VSCode.

basarat
  • 261,912
  • 58
  • 460
  • 511
1

In my case it was the .vscode/tasks.json file. I removed and recreated the file and its all working fine now.

Rjk
  • 1,356
  • 3
  • 15
  • 25
  • Deleting the entire .vscode folder and reloading vscode did the trick for me. I assume I probably only needed to delete `.vscode/tasks.json` – abaga129 Dec 27 '18 at 21:02
1

One possibility is that your tslint.json file may not be in proper JSON format. The tslint.json file as shown when opened in VSCode may analyze it for errors using its jsonc parser, which does not show errors when the last key-value pair has a trailing comma (which is invalid in plain JSON). But, the linting process (or at least ms-vscode.vscode-typescript-tslint-plugin) will silently fail if the tslint.json is not actual JSON.

For example, the following will result in a silent failure, without any indication of where the problem is, due to the trailing comma:

{
  "extends": "tslint:latest",
  "rules": {
    "ordered-imports": false,
    "prefer-for-of": false,
  }
}

Whereas the following will work as expected:

{
  "extends": "tslint:latest",
  "rules": {
    "ordered-imports": false,
    "prefer-for-of": false
  }
}
CertainPerformance
  • 356,069
  • 52
  • 309
  • 320
0

Make sure that you've got a valid tslint.json file in your working directory root. There's a good guide here if you scroll down to the readme - https://github.com/palantir/tslint

Try making a deliberate error to a TS file, and you should see that the error gets underlined with a squiggly line. I

Note: I'm using VSCode 1.3.1, and vscode-tslint 0.5.32.

Andy-Delosdos
  • 3,560
  • 1
  • 12
  • 25
0

I had the same problem as you. For some reason after updating either TSLint or Visual Studio Code, linting stopped working. After cloning the project Zen recommended in the comments, I received an error saying that TSLint wasn't installed. I installed TSLint globally but not as a dev dependency for my project so after running "npm install tslint --save-dev" Visual Studio Code started linting again.

Animal2
  • 75
  • 7
  • You didn't restart vscode after installing tslint globally, right? – Zen Jul 22 '16 at 02:00
  • I've tried restarting multiple times. I've had tslint installed globally for about a month and then I just started having problems recently. – Animal2 Jul 22 '16 at 14:36