PowerShell / PSScriptAnalyzer

Download ScriptAnalyzer from PowerShellGallery
https://www.powershellgallery.com/packages/PSScriptAnalyzer/
MIT License
1.87k stars 378 forks source link

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

Open liamjpeters opened 8 months ago

liamjpeters commented 8 months ago

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 commented 8 months ago

My git-foo is not strong so this is a re-raise of https://github.com/PowerShell/PSScriptAnalyzer/pull/1983 where the full test checks were completed and passed