PowerShell / PowerShell/PSScriptAnalyzer

Accept `-Fix` for `-ScriptDefinition`

Aperta
#1,938 1 commento 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

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

Descrizione

Summary of the new feature

Currently the -Fix parameter is mutual exclusive with the -ScriptDefinition parameter:

Invoke-ScriptAnalyzer -ScriptDefinition 'GCI *' -Fix

Invoke-ScriptAnalyzer: Parameter set cannot be resolved using the specified named parameters. One or more parameters issued cannot; be used together or an insufficient number of parameters were provided.

Proposed technical implementation details (optional)

When both ( -Fixand -ScriptDefinition) parameters, are supplied, I would expect to get a fixed ScriptDefinition back (instead of a [Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.DiagnosticRecord]).
This way, it would be easier to (pester) test a rule with SuggestedCorrections.
(You might of cause check the SuggestedCorrections property but that will not confirm it has been correctly inserted in the script.)
Besides it will allow to fix scripts by creating a fixed copy rather than make sure that you have a backup of your files when using this parameter.

Wishful thinking:

Get-Content *.ps1 | Foreach-Object { Invoke-ScriptAnalyzer -ScriptDefinition $_ | Set-Content "Fixed\$($_.Name)" }

What is the latest version of PSScriptAnalyzer at the point of writing

1.21.0

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 esaminando il punto di ingresso di Invoke-ScriptAnalyzer e la gestione attuale di -ScriptDefinition e -Fix. Verifica come il comando restituisce attualmente le diagnostiche, quindi definisci la copertura per accettare entrambi i parametri, restituire la definizione dello script corretta e confermare che SuggestedCorrections vengano applicate.

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

Valutazione

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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.