PowerShell / PowerShell/PSScriptAnalyzer

Remove-Module PSScriptAnalyzer leaves behavior of removed module version

Aperta
#722 7 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Issue - Discussion
Lingua principale
C#
Stelle
2.2k
Fork
414
Merge medio
13h 1m
PR unite (30g)
2

Descrizione

Removing a version of PSScriptAnalyzer does not remove its behavior from the session. I don't know much about this, but it looks like we're missing code to clean up after a remove.

Version 1.10.0 and 1.11.0 are somewhat different. For example, in 1.11.0, the Settings parameter tab-completes the .psd1 file names in the Settings subdirectory. Also, the PSPlaceOpenBrace and PSPlaceCloseBrace rules do not trigger on a one-line function, such as:

function Test-Brace1 () {"Hello, World"}

However, if you import one version (Import-Module), remove that version (Remove-Module), and then import the other version, the result is the same as if you imported only the first version.

This is important, because the results of the different module versions are perceptibly different.

REPRO:

0. Start a new session, e.g. new console. 
1. ipmo PSScriptAnalyzer -RequiredVersion 1.10.0 -Passthru
2. gmo | rmo
3. ipmo PSScriptAnalyzer -RequiredVersion 1.11.0 -Passthru 

Now, test one of the differing features.

4. Invoke-ScriptAnalyzer -Settings <TAB>    #Fails to tab complete, as in 1.10.0.
5. Invoke-ScriptAnalyzer -ScriptDefinition 'function Test-Brace1 () {"Hello, World"}' -Settings $home\Documents\WindowsPowerShell\Modules\PSScriptAnalyzer\1.11.0\Settings\CodeFormatting.psd1

This returns output that you shouldn't see any more in 1.11.0.

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSPlaceOpenBrace                    Warning                 1     There is no new line after open brace.
PSPlaceCloseBrace                   Warning                 1     Close brace is not on a new line.

The same is true if you reverse the order of the versions.

0. Start a new session, e.g. new console. 
1. ipmo PSScriptAnalyzer -RequiredVersion 1.11.0 -Passthru
2. gmo | rmo
3. ipmo PSScriptAnalyzer -RequiredVersion 1.10.0 -Passthru 

Now, we have 1.10.0 with 1.11.0 behavior:

4. Invoke-ScriptAnalyzer -Settings <TAB>    #Tab completes!
5. Invoke-ScriptAnalyzer -ScriptDefinition 'function Test-Brace1 () {"Hello, World"}' -Settings CodeFormatting

Version 1.10.0 should error on the one-liner, but it doesn't.

PS C:\> Invoke-ScriptAnalyzer -Settings CodeFormatting -ScriptDefinition 'function Test-Brace1 () {"Hello, World"}'
PS C:\>

Strange, I know. If you need more info, let me know. Thanks!

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con la sequenza Import-Module e Remove-Module nella riproduzione, quindi esamina il comportamento di Invoke-ScriptAnalyzer dopo essere passato da PSScriptAnalyzer 1.10.0 a 1.11.0 e viceversa. Confronta il completamento tramite tab delle impostazioni e i risultati di PSPlaceOpenBrace e PSPlaceCloseBrace; il lavoro è completato quando la rimozione di una versione non lascia più il relativo comportamento nella sessione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp, powershell
Ambito
tooling
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.