PowerShell / PowerShell/PSScriptAnalyzer

New Rule Request: Warn against module manifests that load their associated script module as a Nested module

未关闭
#546 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Issue - Discussion
主要语言
C#
星标
2.2k
派生
414
平均合并
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.

贡献指南

打开贡献指南

从这里开始

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

调研方向

首先定位 PSScriptAnalyzer 中的模块检查规则,并跟踪清单和 NestedModules 的表示方式。仅当 issue 中列出的三个条件全部满足时才实现警告,并为匹配的清单和排除的清单添加覆盖测试。

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

评估

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

把新 issue 发到你的邮箱

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