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
- 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