如何在 vscode 中以绿色(警告)而不是红色(错误)显示未使用的导入/本地文件? [英] How can I show unused imports/locals in green (warning) in vscode, rather than red (error)?

查看:91
本文介绍了如何在 vscode 中以绿色(警告)而不是红色(错误)显示未使用的导入/本地文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 vscode 中编写 TypeScript 代码时,未使用的导入显示为错误,并带有红色波浪线下划线:

未使用的局部变量也是如此.当我运行 tsc 作为持续集成测试的一部分时,我很高兴将这些标记为错误,但我宁愿将它们呈现为 vscode 中的绿色警告.更有可能的是我还没有使用 import/local yet,红色错误让我认为存在更严重的问题,例如我正在导入一个不存在的符号.

回到 tslint 实现未使用的导入/本地时,这很好用.但是现在它们是编译器的一部分,很难区分它们.

是否可以仅将这两个编译器错误呈现为警告?

我的 tsconfig.json 包括:

<代码>{编译器选项":{"noUnusedLocals": 真}}

解决方案

TL;DR: 升级到 1.19.0+(目前仅作为内部人员构建版本可用)并且它确实将这些错误报告为默认警告.

<小时>

你很幸运!最近他们合并了一个拉取请求(

When I'm writing TypeScript code in vscode, unused imports are shown as an error, with a red squiggly underline:

The same is true of unused local variables. I'm happy to have these marked as errors when I run tsc as part of my continuous integration tests, but I'd rather have them rendered as green warnings in vscode. It's more likely that I just haven't used the import/local yet, and the red error makes me think there's a more serious problem, e.g. that I'm importing a symbol that doesn't exist.

Back when unused imports/locals were implemented by tslint, this worked great. But now that they're part of the compiler, it's harder to distinguish them.

Is it possible to make just these two compiler errors get rendered as warnings?

My tsconfig.json includes:

{
  "compilerOptions": {
    "noUnusedLocals": true
  }
}

解决方案

TL;DR: Upgrade to 1.19.0+ (currently only available as insiders build version) and it does report these errors as warning by default.


You are lucky! Recently they merged a pull reqests (https://github.com/Microsoft/vscode/pull/37616) which allows users to change the style of reported tsc errors. It is available for VSCode 1.19.0+. As of now it is only available in the VSCode insiders build (which is basically the beta version of the upcoming VSCode).

The setting is called typescript.reportStyleChecksAsWarnings. If the setting is set to true, then all errors of the below types will be reported as warning:

--noUnusedLocals
--noUnusedParameters
--noImplicitReturns
--noFallthroughCasesInSwitch
--allowUnusedLabels
--allowUnreachableCode

In order to enable this setting go to File -> Preferences -> Settings and filter for typescript.reportStyleChecksAsWarnings. Here you can change this setting to true (which is the default in the current insiders build).

这篇关于如何在 vscode 中以绿色(警告)而不是红色(错误)显示未使用的导入/本地文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆