简体   繁体   English

在 VSCode 中禁用 TSLint

[英]Disable TSLint in VSCode

So this feels like this should be such an easy task but it's starting to drive me insane.所以感觉这应该是一件容易的事,但它开始让我发疯。 I can't seem to turn off TSLint or TS or whatever it is that gives me these errors.我似乎无法关闭 TSLint 或 TS 或任何给我这些错误的东西。 I just want the ESLint with my own configured rules, nothing else.我只想要 ESLint 和我自己配置的规则,没有别的。

我只想要 ESLint 错误

Is it built in TS?它是内置在 TS 中的吗? I have disabled TSLint extension (even uninstalled it).我已经禁用了 TSLint 扩展(甚至卸载了它)。 I have set the following rules:我制定了以下规则:

"typescript.format.enable": false,
"typescript.validate.enable": false,

Still gives me error.仍然给我错误。 How do I turn this off?我该如何关闭它?

It seems that the error is coming from the TypeScript extension , which is also handling the JavaScript IntelliSense.错误似乎来自TypeScript 扩展,它也在处理 JavaScript IntelliSense。 Due to some UX ignorance, VSCode prefixes the error with [ts] instead of [js] .由于一些 UX 无知,VSCode 用[ts]而不是[js]前缀错误。

To disable these validations, set要禁用这些验证,请设置

"javascript.validate.enable": false

See this issue for more details.有关更多详细信息,请参阅此问题

I've been hunting around for this answer for the better part of a month now.一个月的大部分时间里,我一直在寻找这个答案。 I found a solution that works in VS Code that isn't a wholesale disabling of all validation for javascript and also did not require that I add files/declarations to a repository that is not mine.我找到了一个适用于 VS Code 的解决方案,它不是全面禁用 javascript 的所有验证,也不需要我将文件/声明添加到不是我的存储库中。

Add this line to your user settings:将此行添加到您的用户设置中:

"javascript.suggestionActions.enabled": false

Unlike "javascript.validate.enable": false (which you should not use), the above setting will remove those annoying [ts] Could not find a declaration file for module errors for untyped module imports in javascript files and it will still play nice with linters and give you appropriate and relevant errors."javascript.validate.enable": false (您不应该使用)不同,上面的设置将删除那些烦人的[ts] Could not find a declaration file for module在 javascript 文件中[ts] Could not find a declaration file for module无类型模块导入的[ts] Could not find a declaration file for module错误[ts] Could not find a declaration file for module文件,它仍然会很好使用 linter 并为您提供适当和相关的错误。

Ctrl-Shift-P (Command Palette) Ctrl-Shift-P (命令面板)

Type Preferences: Open Workspace Settings JSON类型Preferences: Open Workspace Settings JSON

add添加

"tslint.enable":false “tslint.enable”:假

Or要么

"typescript.validate.enable": false “typescript.validate.enable”:假

But beware, as @rawpower has said "We don't want to disable errors, just 'warnings'"但请注意,正如@rawpower 所说:“我们不想禁用错误,只是‘警告’”

Anyways, save and restart VSCode无论如何,保存并重新启动VSCode

Most of the answers turn off the duplicate errors for JavaScript, not TypeScript, like the OP asked about.大多数答案都关闭了 JavaScript 的重复错误,而不是像 OP 询问的 TypeScript。 What worked for me was:对我有用的是:

  1. Uninstall the TSLint vscode extension卸载 TSLint vscode 扩展
  2. Install the ESLint vscode extension安装 ESLint vscode 扩展
  3. Finish configuring ESLint for TypeScript (will now have both "ts errors" and "eslint errors" at this point like the OP).完成为 TypeScript 配置 ESLint (此时将像 OP 一样同时具有“ts 错误”和“eslint 错误”)。
  4. Open settings.json and add this to the bottom: "typescript.validate.enable": false打开 settings.json 并将其添加到底部: "typescript.validate.enable": false

At first, I was concerned that this option would turn off all typescript validation, including eslint, but fortunately that wasn't the case.起初,我担心这个选项会关闭所有打字稿验证,包括 eslint,但幸运的是事实并非如此。 It only disables the built-in vscode typescript validation and leaves eslint alone.它只会禁用内置的 vscode 打字稿验证,而不会影响 eslint。

The most important part is adding "typescript.validate.enable": false to settings.json最重要的部分是将"typescript.validate.enable": false添加到 settings.json

Or, instead of manually editing settings.json, another way is to uncheck the box in the settings menu (ctrl+') :或者,不是手动编辑 settings.json,另一种方法是取消选中设置菜单中的框(ctrl+')

vscode 设置视图以禁用打字稿验证

FYI, you can add it to either your User settings.json (applies to all your projects) or your Workspace settings.json (only applies to the current project) .仅供参考,您可以将其添加到您的 User settings.json (适用于您的所有项目)或您的 Workspace settings.json (仅适用于当前项目)

Just open settings (File -> preference -> Settings) or short cut (Ctl + ,) and search for the 'Javascript Validate'.只需打开设置(文件 -> 首选项 -> 设置)或快捷方式(Ctl + ,)并搜索“Javascript 验证”。

在此处输入图片说明

for newer versions: 对于较新的版本:

in your porjects root folder [.vscode\\settings.json] 在您的项目根文件夹[.vscode \\ settings.json]中

{
    "eslint.validate": [
        "javascript",
        { 
            "language": "typescript",
            "autoFix": true
        }
    ]
}

found in this article , the last paragraph is a "Note for VS Code users" 本文中找到的最后一段是“ VS Code用户注意事项”

For me the solution was to create a jsconfig.json file at root level.对我来说,解决方案是在根级别创建一个jsconfig.json文件。 Inside you can configure the compilerOptions , which did the trick for me after restart of VSCode.在里面你可以配置compilerOptions ,它在重新启动 VSCode 后对我有用。

As far as I understand, VSCode is checking himself the javascript, and believe the TypeScript errors are what you expect.据我了解,VSCode 正在检查自己的 javascript,并相信 TypeScript 错误正是您所期望的。

To stop VSCode from checking my code, and let only the eslint extension check it, I did:为了阻止 VSCode 检查我的代码,并且只让 eslint 扩展检查它,我做了:

  • use eslint to check my javascript (install the extension)使用 eslint 检查我的 javascript(安装扩展)
  • tell vscode not to check my javascript files: in jsconfig.json :告诉 vscode 不要检查我的 javascript 文件:在jsconfig.json
{
   "compilerOptions": {
      "checkJs": false
   }
}

I still see the "eslint" reported errors, and those errors are coherent with command line run of eslint.我仍然看到“eslint”报告的错误,这些错误与 eslint 的命令行运行一致。

PS: jsconfig reference here: https://code.visualstudio.com/docs/languages/jsconfig PS:jsconfig 参考这里: https ://code.visualstudio.com/docs/languages/jsconfig

In VSCode User settings.json, I changed js/ts.implicitProjectConfig.checkJs from true to false在 VSCode User settings.json 中,我将js/ts.implicitProjectConfig.checkJstrue更改为false

// settings.json
{
    "js/ts.implicitProjectConfig.checkJs": false
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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