如何在VS代码中禁止特定的psscriptanalyzer警告 [英] How to suppress specific psscriptanalyzer warning in VS code
问题描述
在VS代码中加载.ps1文件时,我收到了很多这些:
$ null应该在等式比较的左侧。 (PSPossibleIncorrectComparisonWithNull)
由于我不是if($ null -eq $ someVar)订单的粉丝,我想抑制这些警告。
我尝试了什么:
我发现了这个:
https://github.com/PowerShell/PSScriptAnalyzer#suppressing-rules
...哪个领先我尝试在我的文件顶部附近添加以下内容:
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(PSPossibleIncorrectComparisonWithNull,Scope =Function,Target = *)]
...但显然这不是如何使用的,因为警告不会消失...... >
点击VS Code编辑器右下角的PowerShell标签会弹出一个弹出窗口,其中显示配置基于PS语言的设置等等。在那里,搜索PSScriptAnalyzer,我发现我可以完全启用/禁用它(PowerShell> Scrip t分析:启用)。但是,我想禁用这一条规则。
任何人都知道我应该这样做的地方吗?
null应位于相等比较的左侧。 (PSPossibleIncorrectComparisonWithNull)
因为我不喜欢if(
null -eq
someVar)订单,我想抑制这些警告。
我尝试了什么:
我发现了这个:
https://github.com/PowerShell/PSScriptAnalyzer#suppressing-rules < br $> b $ b
...这导致我尝试在文件顶部附近添加以下内容:
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(PSPossibleIncorrectComparisonWithNull,Scope =Function,Target =*)]
...但显然这不是这个怎么样是打算使用,因为警告不会消失......
点击VS Code编辑器右下角的PowerShell标签弹出一个弹出窗口,显示配置基于PS语言的设置等等,在那里,搜索PSScriptAnalyzer,我发现我可以完全启用/禁用它(PowerShell>脚本分析:启用)。但是,我想禁用这一条规则。
任何人都知道我应该在哪里这样做?
I got a bunch of these when loading a .ps1 file in VS Code:
$null should be on the left side of equality comparisons. (PSPossibleIncorrectComparisonWithNull)
Since I'm not a fan of the "if( $null -eq $someVar )" order, I'd like to suppress these warnings.
What I have tried:
I found this:
https://github.com/PowerShell/PSScriptAnalyzer#suppressing-rules
...which lead me to try to add the following near the top of my file:
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSPossibleIncorrectComparisonWithNull", Scope="Function", Target="*")]
...but clearly this is not how this is intended to be used, as the warnings don't go away...
Clicking on the "PowerShell" label on the bottom-right of the VS Code editor brings up a popup showing "Configure PS language-based setting", among other things, and in there, searching for "PSScriptAnalyzer", I found that I can enable/disable it altogether ("PowerShell > Script Analysis: Enable"). However, I'd like to disable just this one rule.
Anyone know where I'm supposed to do that?
null should be on the left side of equality comparisons. (PSPossibleIncorrectComparisonWithNull)
Since I'm not a fan of the "if(
null -eq
someVar )" order, I'd like to suppress these warnings.
What I have tried:
I found this:
https://github.com/PowerShell/PSScriptAnalyzer#suppressing-rules
...which lead me to try to add the following near the top of my file:
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSPossibleIncorrectComparisonWithNull", Scope="Function", Target="*")]
...but clearly this is not how this is intended to be used, as the warnings don't go away...
Clicking on the "PowerShell" label on the bottom-right of the VS Code editor brings up a popup showing "Configure PS language-based setting", among other things, and in there, searching for "PSScriptAnalyzer", I found that I can enable/disable it altogether ("PowerShell > Script Analysis: Enable"). However, I'd like to disable just this one rule.
Anyone know where I'm supposed to do that?
这篇关于如何在VS代码中禁止特定的psscriptanalyzer警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!