PowerShell / PowerShell/PSScriptAnalyzer
Powershell Code Formatter Removing Text From Lines
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- C#
- Sterne
- 2.2k
- Forks
- 414
- Ø Merge
- 13 Std. 1 Min.
- Gemergte PRs (30 T.)
- 2
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der minimalen .psm1-Reproduktion, die die Write-host-Zeile enthält, und vergleiche die Ausgabe von Invoke-Formatter mit dem Ergebnis von Format Document in Visual Studio Code. Erledigt ist es, wenn die Formatierung Write-host in Write-Host ändert, ohne das schließende Anführungszeichen oder -ForegroundColor Red zu entfernen, und die beiden Formatierungspfade konsistente Ergebnisse liefern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- powershell, vscode
- Bereich
- tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100