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

PSAlignAssignmentStatement: Ignore hashtables with a single key-value pair #1986

Merged

Conversation

liamjpeters
Copy link
Contributor

PR Summary

Hashtables with a single key-value pair should be ignored by PSAlignAssignmentStatement as there is nothing to align.

There are other rules that handle whitespace around operators etc which can handle formatting according to the users preference.

Currently:

Invoke-Formatter -ScriptDefinition "@{'Key'='Value'}" -Settings @{
    Rules = @{
        PSAlignAssignmentStatement = @{
            Enable = $true
            CheckHashtable = $true
        }
    }
}

Results in:

@{'Key' ='Value'}

Note the space added after the hashtable key

Resolves #1979

PR Checklist

@liamjpeters
Copy link
Contributor Author

My git-foo is not strong so this is a re-raise of #1983 where the full test checks were completed and passed

Copy link
Collaborator

@bergmeister bergmeister left a comment

Choose a reason for hiding this comment

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

Nice to fix this undesired side effect in this case. the formatting rules have so many special oddities 😅

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.

Thanks!

@andyleejordan andyleejordan enabled auto-merge (squash) February 19, 2025 18:24
…g on a single line, and not checked for violations.
@andyleejordan andyleejordan force-pushed the #1979IgnoreHashtablesWithASingleKVP branch from 57cb24b to d831fba Compare February 19, 2025 18:28
@andyleejordan andyleejordan merged commit 20135fb into PowerShell:main Feb 19, 2025
4 checks passed
@liamjpeters liamjpeters deleted the #1979IgnoreHashtablesWithASingleKVP branch February 21, 2025 11:50
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.

Adds whitespace around operators with whitespaceAroundOperator set to false in some cases
3 participants