-
Notifications
You must be signed in to change notification settings - Fork 382
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
whitespaceBetweenParameters Removing Redirectors #2000
Comments
Thanks @nixuno we were able to reproduce this |
This is quite an interesting one 😀. A slightly simplified repro in PSScriptAnalyzer is: Invoke-Formatter -ScriptDefinition 'Invoke-Foo 3>&1 1>&1 2>&1' -Settings @{
Rules = @{
PSUseConsistentWhitespace = @{
Enable = $true
CheckParameter = $true
}
}
} Results in: Invoke-Foo 1>&1 The For each PSScriptAnalyzer/Rules/UseConsistentWhitespace.cs Lines 399 to 400 in e1dc126
It's checking then that each one sequentially is separated by a 1 character gap. PSScriptAnalyzer/Rules/UseConsistentWhitespace.cs Lines 410 to 411 in e1dc126
It seems to be making the implicit assumption that the direct children of the Looking at the AST of our example
We see that evidentially, the
I'm not smart enough to confirm this within the main Powershell Repo's parser - but I've tried with various orders of My unrefined naive solution would be to sort the command parameters (the direct children of the This works as expected and our repro code correctly produces: Invoke-Foo 3>&1 1>&1 2>&1 I would need to look at how badly this sorting impacts performance and for any edge cases. |
Prerequisites
Summary
When formatting the following PowerShell while
powershell.codeFormatting.whitespaceBetweenParameters = true
, it removes two of the redirectors:Pre-Format
Post-Format
I would expect the redirectors to be left alone.
PowerShell Version
Visual Studio Code Version
Extension Version
[email protected]
Steps to Reproduce
test.ps1
:Shift + Alt + F
to format the document.Visuals
No response
Logs
No response
The text was updated successfully, but these errors were encountered: