You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
codeFormatting.IgnoreOneLineBlock / hashtable problem #1284
if ($test-eq$null) {$test=@{}}
if ($test-eq$null) {
$test=@{ }
}
Expected behavior
This is actually what happens when $test is an array and what you should expect from an hashtable assignment.
if ($test-eq$null) { $test=@() }
if ($test-eq$null) {
$test=@()
}
Actual behavior
This is what actually happens with hashtables.
if ($test-eq$null) { $test=@{ }
}
if ($test-eq$null) {
$test=@{ }
}
Environment data
> $PSVersionTable
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
> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.18.0
(This is the version that comes with the latest versions of VSCode, from which this is used)
Thanks for the detailed report.
First of all, I suggest to install PSSA 1.18.1 for improved formatting and speed (the extension will start picking it up after the next restart of the shell or VSCode).
Secondly, it still happens with the newer version unfortunately. The 1st line is actually sufficient for a repro if one includes the newline in the formatting selection as well:
Activity
bergmeister commentedon Jul 8, 2019
Thanks for the detailed report.
First of all, I suggest to install PSSA 1.18.1 for improved formatting and speed (the extension will start picking it up after the next restart of the shell or VSCode).
Secondly, it still happens with the newer version unfortunately. The 1st line is actually sufficient for a repro if one includes the newline in the formatting selection as well:
Running
Invoke-Formatterwith default settings can repro as well and after having attached the culprit is on the lines below as the rule seems to be simply token basedhttps://github.com/PowerShell/PSScriptAnalyzer/blob/master/Rules/PlaceCloseBrace.cs#L410-L414
One would need to enhance this piece of code to lookup the brace in the AST to see if it is an
HashTableAstand if so, ignore it.There is actually some logic to exclude 1 line hashtable but that should be improved to exclude hashtables in general:
https://github.com/PowerShell/PSScriptAnalyzer/blob/master/Rules/PlaceCloseBrace.cs#L135-L137
UPDATE: I have a found a fix, will open a PR in the next days. Here is a preview of it.