Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSUseConsistentWhitespace: Correctly fix whitespace between command parameters when parameter value spans multiple lines #2064

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

liamjpeters
Copy link
Contributor

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:

fo-baz

fo-baz

fo-baz

Fixes #2060

PR Checklist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpected string with powershell.codeFormatting.whitespaceBetweenParameters enabled
1 participant