◐ Shell
clean mode source ↗

PSUseConsistentWhitespace: Correctly fix whitespace between command parameters when parameter value spans multiple lines by liamjpeters · Pull Request #2064 · PowerShell/PSScriptAnalyzer

PR Summary

Changes the suggested correction extent of PSUseConsistentWhitespace's parameter spacing violations.

When enabled, the CheckParameter setting of this rule checks the spacing between parameters of a command.

An erroneous correction extent was being generated when parameter values spanned multiple lines (such as for arrays, scriptblocks, and hashtables.

For instance, using the below settings to isolate only the CheckParameter part of the rule:

$Settings = @{
    IncludeRules = @('PSUseConsistentWhitespace')
    Rules        = @{
        PSUseConsistentWhitespace = @{
            Enable                                  = $true
            CheckInnerBrace                         = $false
            CheckOpenBrace                          = $false
            CheckOpenParen                          = $false
            CheckOperator                           = $false
            CheckPipe                               = $false
            CheckPipeForRedundantWhitespace         = $false
            CheckSeparator                          = $false
            CheckParameter                          = $true
            IgnoreAssignmentOperatorInsideHashTable = $false
        }
    }
}

Running the formatter against:

foo { 
    bar
}  -baz

foo @{ 
    1 = 1
}  -baz

foo @(
    1
)  -baz

Note: There are multiple spaces before each of the -baz parameters

Resulted in:

Fixes #2060

PR Checklist