在VisualStudioCode中运行的Angular应用程序中,TSLint扩展抛出错误

我最近开始看到 TSLint 错误。它们看起来像这样:

不使用为“/Users/myname/myproject/client/src/app/likes/likee/likee.component.ts”找到的本地 TSLint 版本。要从当前工作区启用代码执行,您必须启用工作区库执行。

当我打开它们时,我在我的 .ts 文件中看到它们,它在每个 .ts 页面的第一行显示一条黄色波浪线。

我在TSLint网站上看到它说它已被弃用。

问题 1 - 这些错误的原因是什么,为什么我会突然看到它们?

问题 2 - 我应该卸载 Visual Studio Code TSLint 扩展并安装 ESLint 扩展吗?

回答

就像@Tu?n Nguy?n描述的那样,您需要:

  1. Ctrl + Shift + P,转到命令面板

  2. 在 VS Code 顶部弹出的输入中,开始输入

    TSLint: Manage workspace library execution"
    

    并击中Enter键。

  3. 从替换输入的菜单中,选择enable workspace library execution并再次Enter按键。

  • Hi. Can you tell me why I'm suddenly seeing this? And wether I should uninstall TSLint and use ESLint instead, like the documentation says? It says it's been deprecated.
  • Is there any way to make this change "sticky"? Enabling workspace library execution works, but it seems when I close VS Code and re-open the same project, I have to enable it again.
  • @CollinM.Barrett From the same menu choose "Always enable workspace library execution"
  • @user1186050 Yes, you should uninstall TSLint and use ESLint as a recommended approach. While, this is visible as Microsoft may have done needful things to get rid of TSLint and mark it deprecated. Check my answer above: https://stackoverflow.com/a/65288426/7629107.

回答

您应该转到 VScode 中的命令面板以搜索 TSLint:管理工作区库执行。并启用工作区库执行

  • @user1186050 ctrl + shift + p > TSLint: Manage workspace library execution > Enter > Enable workspace library execution

回答

尽管@Tu?n Nguy?n 给出的答案有效,但不建议这样做。

根据 MS 文档
https://marketplace.visualstudio.com/items?itemName=ms-vscode.vscode-typescript-tslint-plugin,此答案将替换用本地定义的全局 TS lint 配置,可以轻松操作出于安全原因,也不建议这样做。

截屏:

推荐方法:

根据 MS Docs,https: //code.visualstudio.com/api/advanced-topics/tslint-eslint-migration,最近更新(12/11/2020),您应该从 TSLint 迁移到 ESLint。

这可能是每个人都在寻找修复程序的原因,因为 MS 最近做了一些必要的事情。:)

脚步:

  1. npm install --save-dev eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin (安装 ESlint 和 TSLint)
  2. npx tslint-to-eslint-config(这将安装实用工具并使配置更容易。安装后将创建一个新的.eslintrc.js。也会对.vscode/settings.json进行更改。)
  3. 从 VS Code 中禁用/卸载 TS lint。
  4. 然后,您可以在package.json文件中将脚本作为 -放置"lint": "eslint -c .eslintrc.js --ext .ts <mySrcFolder>"。(这会告诉 ESLint 去寻找 TSLint)

但是,您可能应该更生动地查看链接中的步骤,以便正确并相应地执行步骤。


回答

Ctrl+ Shift+P打开命令面板。

在 VS Code 顶部弹出的输入中,写

TSLint: Manage workspace library execution

从替换输入的菜单中,选择

Enable Workspace Library Execution


回答

Ctrl+ Shift+转到命令面板P

在 VS Code 顶部弹出的输入中,开始输入

TSLint:管理工作区库执行”并点击Enter.

从替换输入的菜单中,选择启用工作区库执行,然后再次点击Enter


回答

我以这种简单的方式解决了这个问题:

文件 -> 将工作区另存为...

通过保存工作区,vscode 检测一些库并在文件中更好地工作

  • Thanks! I couldn't find the TSLint Manage Workspace on the Command Palette as others suggested, but after saving the workspace it appeared and worked just fine!

以上是在VisualStudioCode中运行的Angular应用程序中,TSLint扩展抛出错误的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>