PowerShell / PowerShell/PSScriptAnalyzer
When a line ends in an operator, automatically indent the next line since it is part of the same code statement
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- C#
- Estrellas
- 2.2k
- Forks
- 414
- Merge medio
- 13 h 1 min
- PR fusionados (30 d)
- 2
Descripción
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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza rastreando el comportamiento existente de indentación de la pipe | en el formateador de PSScriptAnalyzer y cómo se clasifican los operadores de continuación de línea. Extiende las mismas reglas a operadores como =, + y -, y después verifica la salida formateada con los ejemplos y el comportamiento existente de la pipe.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- powershell
- Área
- tooling
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100