PowerShell / PowerShell/PSScriptAnalyzer
New Rule Request: Warn against module manifests that load their associated script module as a Nested module
Nessuno ha ancora preso questa issue.
- Lingua principale
- C#
- Stelle
- 2.2k
- Fork
- 414
- Merge medio
- 13h 1m
- PR unite (30g)
- 2
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia individuando le regole di ispezione dei moduli in PSScriptAnalyzer e tracciando il modo in cui vengono rappresentati i manifesti e NestedModules. Implementa l’avviso solo quando sono soddisfatte tutte e tre le condizioni elencate nell’issue e aggiungi la copertura per i manifesti corrispondenti ed esclusi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- csharp, powershell
- Ambito
- devtools
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100