简体   繁体   中英

How can I use TSLint in VS Code?

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?

在此输入图像描述

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.

在此输入图像描述

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

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

When in doubt. Restart VSCode.

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

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.

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.

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
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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