PowerShell / PowerShell/PSScriptAnalyzer
New Rule Request: Warn against module manifests that load their associated script module as a Nested module
還沒有人認領這個 Issue。
- 主要語言
- C#
- 星號
- 2.2k
- 分支
- 415
- 平均合併
- 13 小時 1 分鐘
- 30 天內合併 PR
- 2
描述
The Microsoft.PowerShell.Archive module uses a weird way of loading the script module file. Instead of identifying the script module using the RootModule/ModuleToProcess key in the manifest, it uses NestedModules instead. This is unusual, unexpected, and will very likely have side effects. An example of an existing side effect that @jaykul found is:
- it obscures your module scope, so to inspect the internal variables/state of the module, they can't simply use this technique:
&(gmo Microsoft.PowerShell.Archive) {...}
Instead they have to do this:
&(gmo Microsoft.PowerShell.Archive) {&(gmo Microsoft.PowerShell.Archive) { .... }}
With this approach to module design, there are far more unknowns then there are knowns (can they even access their own metadata, assign an OnClose event handler that works as expected, etc.?).
Regardless of the unknowns, this should be considered an anti-pattern unless (a) there is some benefit to designing modules this way, and (b) there won't be any bugs when designing modules this way.
I recommend creating a rule for modules (once modules are inspected as modules) that warns against this design. It can't really be created until modules are inspected as modules, because it is perfectly valid to create a manifest module that doesn't have an associated script/binary module file and that simply provides a distribution mechanism for multiple modules as a bundle. With that in mind, this should only warn when:
(a) a module manifest defines one or more NestedModules; and
(b) the same manifest does not define RootModule/ModuleToProcess; and
(c) one of the NestedModules is a script or binary module in the same folder as the manifest with the same name.
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
首先定位 PSScriptAnalyzer 中的模組檢查規則,並追蹤資訊清單和 NestedModules 的表示方式。僅當 issue 中列出的三個條件全部滿足時才實作警告,並為符合的資訊清單和排除的資訊清單新增覆蓋測試。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- csharp, powershell
- 領域
- devtools
- Issue 類型
- 功能
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100