Skip to content

PSUseConsistentWhitespace: Ignore whitespace between separator and comment#2065

Merged
andyleejordan merged 1 commit into
PowerShell:mainfrom
liamjpeters:#1842PSUseConsistentWhitespaceCommentAfterSeparator
Feb 25, 2025
Merged

PSUseConsistentWhitespace: Ignore whitespace between separator and comment#2065
andyleejordan merged 1 commit into
PowerShell:mainfrom
liamjpeters:#1842PSUseConsistentWhitespaceCommentAfterSeparator

Conversation

@liamjpeters

@liamjpeters liamjpeters commented Feb 25, 2025

Copy link
Copy Markdown
Contributor

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

…e violations between a separator and a comment
@liamjpeters

Copy link
Copy Markdown
Contributor Author

Fixes #1842

@andyleejordan andyleejordan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great.

@andyleejordan andyleejordan enabled auto-merge (squash) February 25, 2025 19:38
@andyleejordan andyleejordan merged commit d30f10f into PowerShell:main Feb 25, 2025
@liamjpeters liamjpeters deleted the #1842PSUseConsistentWhitespaceCommentAfterSeparator branch February 25, 2025 20:46
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.

PSUseConsistentWhitespace should not flag for comments after a separator

2 participants