PowerShell / PowerShell/PSScriptAnalyzer
PSUseDeclaredVarsMoreThanAssignments is not aware of the scriptblock context (invocation or dot-sourcing)
未關閉
還沒有人認領這個 Issue。
Area - PSUseDeclaredVarsMoreThanAssignments
Area - Rules
- 主要語言
- C#
- 星號
- 2.2k
- 分支
- 415
- 平均合併
- 13 小時 1 分鐘
- 30 天內合併 PR
- 2
描述
Steps to reproduce
Extracted from here but similar issues also reported in #711
It’s a PSSA bug. I get the same warning with:
$totalSize = 0
. { $totalSize += 1 }
$totalSize
PSSA is apparently analyzing each script block independently.
It needs to recognize when a script block is dot sourced and analyze it in the context of where it is >invoked. This isn’t always possible, but it’s usually easy to do when using ForEach-Object (which dot >sources like this).
In trying some variants on the idea, it seems like there are multiple bugs:
$totalSize = 0
function foo {
$x = $totalSize + 1
$totalSize = $x # Should warn, doesn't (bug)
}
& {
$x = $totalSize + 1
$totalSize = $x # Should warn, doesn't (bug)
}
. {
$x = $totalSize + 1
$totalSize = $x # Should not warn, doesn't (no bug)
}
. {
$totalSize += 1 # Should not warn, does (bug)
}
$totalSize
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 PSUseDeclaredVarsMoreThanAssignments 的實作開始,重現 issue 中的 invocation、dot-sourcing、function 和 scriptblock 範例。將每項診斷與 comments 中描述的預期行為進行比較;完成的標準是 analyzer 能夠處理這些情境,且沒有 false positives 或遺漏的警告。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- csharp, powershell
- 領域
- tooling
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100