◐ Shell
clean mode source ↗

PSUseConsistentWhitespace: Ignore whitespace between separator and comment by liamjpeters · Pull Request #2065 · PowerShell/PSScriptAnalyzer

PR Summary

When checking for consistent whitespace between separators, using:

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

Whitespace between a separator and subsequent start of a comment is flagged as a violation. When formatting, it is removed.

So something such as:

$Array = @(
    'Foo',     # Comment Line 1
    'FizzBuzz' # Comment Line 2
)

Is fixed to:

$Array = @(
    'Foo', # Comment Line 1
    'FizzBuzz' # Comment Line 2
)

This doesn't seem like desirable behaviour.

This PR ignores whitespace between separators and the start of a comment.

There were no tests around the CheckSeparator parameter, so I've added some.

Fixes #1842

PR Checklist