VS Code中TSLint无法正常工作问题咨询
Let’s walk through the most likely fixes to get TSLint working properly in your setup:
Install local dependencies (critical!)
Global installs oftslintandtypescriptaren’t enough—VS Code’s TSLint extension prioritizes project-local packages for compatibility. Run this in your project root:npm install --save-dev tslint tslint-react typescriptFix your
tslint.jsonsyntax
JSON files don’t support single-line//comments, which is breaking your configuration file. Remove those comments and use valid JSON:{ "extends": ["tslint:latest", "tslint-react"], "rules": { "jsx-wrap-multiline": false, "max-line-length": false, "no-implicit-dependencies": [true, "dev"], "no-var-requires": false, "indent": false } }Verify VS Code extension status
Open the Extensions panel (Ctrl+Shift+X), search for the TSLint extension, and make sure it’s enabled. If it shows any error badges, try disabling and re-enabling it, or reinstalling the extension entirely.Check VS Code settings for TSLint
Open your settings (Ctrl+,), search for "tslint", and confirm these key settings:tslint.enableis set totruetypescript.tsdkpoints to your local TypeScript installation (e.g.,./node_modules/typescript/librelative to your project root)
Reload the VS Code window
Sometimes extensions need a refresh to pick up new dependencies or config changes. Press Ctrl+Shift+P, type "Reload Window", and run the command.Check version compatibility
TSLint is no longer maintained, and newer TypeScript versions (4.0+) aren’t supported by TSLint 6.x. Run these commands to check your versions:tslint --version tsc --versionIf your TypeScript version is too new, you’ll need to either downgrade TypeScript to 3.9.x or migrate to ESLint (the recommended linter for modern TypeScript/React projects).
Inspect the TSLint output for errors
Open the VS Code Output panel (Ctrl+Shift+U), select "TSLint" from the dropdown menu. Any errors here (like config parsing failures or missing dependencies) will point you directly to the issue.
内容的提问来源于stack exchange,提问作者blankface

