PowerShell / PowerShell/PSScriptAnalyzer
New Rule Request: Warn against module manifests that load their associated script module as a Nested module
まだ誰も着手していません。
- 主要言語
- C#
- スター
- 2.2k
- フォーク
- 414
- 平均マージ
- 13時間 1分
- マージ済み PR(30日)
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、PSScriptAnalyzer のモジュール検査ルールを見つけ、マニフェストと NestedModules がどのように表現されているかを追跡します。issue に記載されている 3 つの条件がすべて成立する場合にのみ警告を実装し、一致するマニフェストと除外されるマニフェストのカバレッジを追加します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- csharp, powershell
- 領域
- devtools
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100