Repository navigation
PSUseConsistentWhitespace is not consistent with hash @{} and array @() #1346
Copy link
Copy link
Closed
Labels
Description
Steps to reproduce
Simple example:
$Array = @(); $Array.Count
$Hash = @{}; $Hash.CountWith a lint.psd1 of:
@{
IncludeDefaultRules = $True
Rules = @{
PSUseConsistentWhitespace = @{
Enable = $True
}
}
}Execute
Invoke-ScriptAnalyzer -Path tmp.ps1 -settings lint.psd1Expected behavior
I would expect
- Empty hash declarations to not cause a whitespace warning
OR - Empty array declarations to follow the same guidelines of empty hash declarations (requiring a space)
I would prefer option 1.
Actual behavior
Environment data
PS C:\tmp> System.Collections.Hashtable
Name Value
---- -----
PSVersion 5.1.17763.503
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.503
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
PS C:\tmp> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { .ToString()}
1.18.3
Reactions are currently unavailable

Activity
bergmeister commentedon Sep 24, 2019
I agree that option 1 seems to be better. The formatting/style rules are all token based, therefore the fix might be as simple as making the rule aware of the 'type' of brace. I'd hope the rule already recognizes hashtables correctly, maybe it's just the special case of an empty hashtable that needs fixing.
PlagueHO commentedon Oct 5, 2019
Christoph Bergmeister (@bergmeister) - we've just run into this over in the DSC Resource kit as well when implementing new hashtable style validation rules.
The preferred style we'd like to be able to enforce/detect would be:
@{}@()So, ideally being able to specify an option to include/exclude white space would be ideal.
CC: Svilen (@SSvilen), Johan Ljunggren (@johlju)
bergmeister commentedon Oct 7, 2019
Apologies, this is caused by the new
CheckInnerBracefeature ofPSUseConsistentWhitespacethat I added in1.18.0. I opened PR #1349 with a fix for it.PlagueHO commentedon Oct 8, 2019
Thanks Christoph Bergmeister (@bergmeister) 🥇