PowerShell / PowerShell/PSScriptAnalyzer

Global variables are erroneously reported as "never used"

未关闭
#1,300 4 条评论 3 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Area - PSUseDeclaredVarsMoreThanAssignments
主要语言
C#
星标
2.2k
派生
414
平均合并
13 小时 1 分钟
30 天内合并 PR
2

描述

System Details Output

### VSCode version: 1.36.1 2213894ea0415ee8c85c5eea0d0ff81ecc191529 x64

### VSCode extensions:
bierner.lit-html@1.11.0
mikeburgh.xml-format@1.0.2
MS-CEINTL.vscode-language-pack-de@1.36.2
ms-vscode.powershell@2019.5.0
msjsdiag.debugger-for-chrome@4.11.6
slevesque.vscode-hexdump@1.7.2


### PSES version:

### PowerShell version:

Name                           Value
----                           -----
PSVersion                      5.1.16299.1146
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.16299.1146
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
Issue Description

PowerShell extension reports global variables as assigned but not used when they are not used from within a .psm1 module file. However, global variables may be used by scripts outside that module importing it.

Expected Behaviour

Global variables should never be reported as being unused.

Actual Behaviour

PowerShell extension reports global variables as assigned but not used when they are not used from within a .psm1 module file.

global variables error

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

未指定源文件、测试或入口点。首先定位用于报告已赋值但未使用变量的分析器逻辑,以及覆盖模块或全局变量作用域的测试。确认当前行为,然后更新相关测试预期,使全局变量不会被报告为未使用,并运行受影响的分析器测试。

由索引模型根据 Issue 内容生成。

评估

技术栈
csharp, powershell
领域
tooling
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。