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 is not consistent with hash @{} and array @() #1346

Closed
steveredden opened this issue Sep 24, 2019 · 4 comments · Fixed by #1349
Closed

PSUseConsistentWhitespace is not consistent with hash @{} and array @() #1346

steveredden opened this issue Sep 24, 2019 · 4 comments · Fixed by #1349

Comments

@steveredden
Copy link

Steps to reproduce

Simple example:

$Array = @(); $Array.Count
$Hash = @{}; $Hash.Count

With a lint.psd1 of:

@{
    IncludeDefaultRules = $True
    Rules = @{
        PSUseConsistentWhitespace = @{
            Enable = $True
        }
    }
}

Execute

Invoke-ScriptAnalyzer -Path tmp.ps1 -settings lint.psd1

Expected behavior

I would expect

  1. Empty hash declarations to not cause a whitespace warning
    OR
  2. Empty array declarations to follow the same guidelines of empty hash declarations (requiring a space)

I would prefer option 1.

Actual behavior

image

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
@bergmeister
Copy link
Collaborator

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
Copy link

PlagueHO commented Oct 5, 2019

@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:

  • Empty hashtable: @{}
  • Empty array: @()

So, ideally being able to specify an option to include/exclude white space would be ideal.

CC: @SSvilen, @johlju

@bergmeister
Copy link
Collaborator

Apologies, this is caused by the new CheckInnerBrace feature of PSUseConsistentWhitespace that I added in 1.18.0. I opened PR #1349 with a fix for it.

@PlagueHO
Copy link

PlagueHO commented Oct 8, 2019

Thanks @bergmeister 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants