PowerShell / PowerShell/PSScriptAnalyzer

Powershell Code Formatter Removing Text From Lines

Aperta
#1,655 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

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

Descrizione

Hi,

I am trying to track down an issue where the Powershell code formatter is run against a psm1 file but does not seem to do
anything at all. I started pasting individual functions of the psm1 file into a new file to see if perhaps it was confused by a certain piece of code. I have yet to establish why it does not appear to do anything on the original file at all. It did run on the new file but it messed up one function that contained the following line of code. I was able to replicate this issue by creating a new .psm1 file that only contains the string below and then running the Format Document against it

Code Before Running Formatter

Write-host "Error: File '$settingsfile' does not exist" -ForegroundColor Red

Code After Running Formatter

Write-Host "Error: File '$settingsfile'-ForegroundColor Red

What is odd is that if you run the line above through Invoke-Formatter, it does not mess up the result. But if you use SHIFT-ALT-F, it does. If you use Format Selection it does nothing in code. It was supposed to change Write-host to Write-Host.

Apart from the fact that it actually removes code it is not supposed to remove, what is the best way to debug this. The result returned by Invoke-Formatter does not seem to correspond what is put back in the psm1 file.

Visual Studio Code Version: 1.52.1
Powershell Extension: v2020.6.0
PSVersion 5.1.17763.1490
Windows Version: 10.0.17763.0 - Windows 2019

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 riproduzione minima in .psm1 contenente la riga Write-host e confronta l'output di Invoke-Formatter con il risultato di Format Document in Visual Studio Code. È completato quando la formattazione cambia Write-host in Write-Host senza rimuovere la virgoletta di chiusura o -ForegroundColor Red e i due percorsi di formattazione producono risultati coerenti.

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

Valutazione

Stack tecnologico
powershell, vscode
Ambito
tooling
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 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.