When a line ends in an operator, automatically indent the next line since it is part of the same code statement
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 35/100
- Issue-Typ
- Feature
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Veraltet
- Tech-Stack
- powershell
- Bereich
- tooling
Rechercherichtung
Beginnen Sie damit, das bestehende Einrückungsverhalten für die Pipe | im Formatter von PSScriptAnalyzer nachzuverfolgen und zu untersuchen, wie Zeilenfortsetzungsoperatoren klassifiziert werden. Erweitern Sie dieselben Regeln auf Operatoren wie =, + und -, und überprüfen Sie anschließend die formatierte Ausgabe anhand der Beispiele und des bestehenden Pipe-Verhaltens.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Summary of the new feature
As a user, when a line ends in a line continuation operator (=, +, -, etc.), I would like the next line to be indented so that it is clear both lines are part of the same statement, and that the 2nd line is not the start of a new code statement. This behaviour is already implemented for the pipe | operator, and it would be great if the other operators followed the same rules. This behaviour would also match the default behaviour of other languages, such as C# in Visual Studio. In VS Code, this behaviour is controlled for the pipe operator with the powershell.codeFormatting.pipelineIndentationStyle setting.
For example, when using the VS Code setting powershell.codeFormatting.pipelineIndentationStyle = IncreaseIndentationForFirstPipeline, the code is currently formatted like this:
$result =
Get-Process |
Select-Object -First 1
I would prefer = to follow the same rules as | and have the code formatted like this:
$result =
Get-Process |
Select-Object -First 1
In this small example it may look silly to not just do:
$result = Get-Process |
Select-Object -First 1
However, sometimes with fully qualified namespaces and descriptive variable names, the left-side of the equal operator may get very lengthy, such as:
[System.Collections.ArrayList] $listOfCustomersWithValidDriversLicenses = Get-CustomersFromCmdletWithAVeryLongName -Country Canada -AreaCode 123
This would look much better and prevent horizontal scrolling as:
[System.Collections.ArrayList] $listOfCustomersWithValidDriversLicenses =
Get-CustomersFromCmdletWithAVeryLongName -Country Canada -AreaCode 123
Currently, VS Code formats the code like this:
[System.Collections.ArrayList] $listOfCustomersWithValidDriversLicenses =
Get-CustomersFromCmdletWithAVeryLongName -Country Canada -AreaCode 123
The current formatting makes it easy to overlook that the results returned from Get-CustomersFromCmdletWithAVeryLongName are being saved in a variable.
The example above is for the = operator, but I think it would make sense to do the same thing for +, -, and any other line continuation operators (i.e. that don't require a backtick ` to have the statement continue onto the next line).
Aside: I originally posted this issue in the vscode-powershell repo here, but I think this is the proper place for this feature request.
What is the latest version of PSScriptAnalyzer at the point of writing
The latest stable version of PSScriptAnalyzer is currently v1.22.0.
- Vorherrschende Sprache
- C#
- Sterne
- 2.2k
- Forks
- 415
- Ø Merge
- 13 Std. 1 Min.
- Gemergte PRs (30 T.)
- 2
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus PowerShell/PSScriptAnalyzer
-
Up-for-Grabs
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 78/100
PowerShell/PSScriptAnalyzer#2213 · 2 Kommentare ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 72/100
PowerShell/PSScriptAnalyzer#2217 · 1 Kommentar ·
-
PSUseConsistentIndentation double-indents attribute bodies that open a scriptblock (`[Attr({ … })]`) Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 70/100
PowerShell/PSScriptAnalyzer#2216 · 2 Kommentare ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 68/100
PowerShell/PSScriptAnalyzer#2211 ·
-
`PSPlaceOpenBrace` and `PSPlaceCloseBrace` leave trailing whitespace when expanding one-line blocks Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 70/100
PowerShell/PSScriptAnalyzer#2210 ·
Alle Issues in PowerShell/PSScriptAnalyzer
Ähnliche Issues
-
Status: Waiting triage Type: Bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
nanoframework/Home#1857 ·
-
kind/bug kind/regression
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
unoplatform/uno.toolkit.ui#1646 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
nightscout/nocturne#1379 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
elastic/esql-dotnet#47 ·
-
port: add go-steam fork Offen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 85/100