PowerShell / PowerShell/PSScriptAnalyzer

PSUseConsistentIndentation not respected for pipeline chain operators.

Abierto
#2,120 0 comentarios 0 reacciones 0 asignados Ver en GitHub

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

When using natural line continuation with IncreaseIndentationForFirstPipeline (or IncreaseIndentationAfterEveryPipeline) enabled and pipeline chain operators, it does not format as expected like with regular pipeline operators.

Before submitting a bug report:

  • Make sure you are able to repro it on the latest released version
  • Perform a quick search for existing issues to check if this bug has already been reported

Steps to reproduce

$scriptDefinition = @'
Get-Item "C:\someItem" &&
Get-Item "C:\someItem" &&
Get-Item "C:\someItem"
'@

$settings = @{
    IncludeRules = @("PSUseConsistentIndentation")
    Rules = @{
        PSUseConsistentIndentation = @{
            Enable              = $true
            IndentationSize     = 4
            PipelineIndentation = 'IncreaseIndentationForFirstPipeline'
            Kind                = 'space'
        }
    }
}

Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings
Get-Item "C:\someItem" &&
Get-Item "C:\someItem" &&
Get-Item "C:\someItem"

Expected behavior

$scriptDefinition = @'
Get-Item "C:\someItem" &&
Get-Item "C:\someItem" &&
Get-Item "C:\someItem"
'@

$settings = @{
    IncludeRules = @("PSUseConsistentIndentation")
    Rules = @{
        PSUseConsistentIndentation = @{
            Enable              = $true
            IndentationSize     = 4
            PipelineIndentation = 'IncreaseIndentationForFirstPipeline'
            Kind                = 'space'
        }
    }
}

Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings
Get-Item "C:\someItem" &&
    Get-Item "C:\someItem" &&
    Get-Item "C:\someItem"

Actual behavior

$scriptDefinition = @'
Get-Item "C:\someItem" &&
Get-Item "C:\someItem" &&
Get-Item "C:\someItem"
'@

$settings = @{
    IncludeRules = @("PSUseConsistentIndentation")
    Rules = @{
        PSUseConsistentIndentation = @{
            Enable              = $true
            IndentationSize     = 4
            PipelineIndentation = 'IncreaseIndentationForFirstPipeline'
            Kind                = 'space'
        }
    }
}

Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings
Get-Item "C:\someItem" &&
Get-Item "C:\someItem" &&
Get-Item "C:\someItem"

If an unexpected error was thrown then please report the full error details using e.g. $error[0] | Select-Object *

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      7.4.11
PSEdition                      Core
GitCommitId                    7.4.11
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.24.0
1.22.0

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza reproduciendo el ejemplo con Invoke-Formatter y la configuración de PSUseConsistentIndentation mostrada en la issue, comparando los operadores de pipeline normales con los operadores de encadenamiento de pipeline. Sigue la ruta del formateador que gestiona la continuación natural de línea y confirma que la salida coincide con la indentación esperada de cuatro espacios para los comandos encadenados.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
csharp, powershell
Área
tooling
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
48/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.