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: Ignore whitespace between separator and comment #2065

Conversation

liamjpeters
Copy link
Contributor

@liamjpeters liamjpeters commented Feb 25, 2025

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

Fixes #1842

Copy link
Member

@andyleejordan andyleejordan left a comment

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
4 checks passed
@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