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
) -bazNote: There are multiple spaces before each of the
-bazparameters
Resulted in:
Fixes #2060
PR Checklist
- PR has a meaningful title
- Use the present tense and imperative mood when describing your changes
- Summarized changes
- Change is not breaking
- Make sure all
.cs,.ps1and.psm1files have the correct copyright header - Make sure you've added a new test if existing tests do not effectively test the code changed and/or updated documentation
- This PR is ready to merge and is not Work in Progress.
- If the PR is work in progress, please add the prefix
WIP:to the beginning of the title and remove the prefix when the PR is ready.
- If the PR is work in progress, please add the prefix