-
Notifications
You must be signed in to change notification settings - Fork 378
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
Adds whitespace around operators with whitespaceAroundOperator
set to false in some cases
#1979
Comments
This looks to be being caused by rule The simplest case where I can reproduce this is: Invoke-Formatter -ScriptDefinition "@{'Key'='Value'}" -Settings @{
Rules = @{
PSAlignAssignmentStatement = @{
Enable = $true
CheckHashtable = $true
}
}
} Results in: @{'Key' ='Value'} The rule seems to be opinionated about there being a single space after the key name when it does it's alignment. The rule has some logic to check if the hashtable is on multiple lines and, if not, should not check it for violations. This logic does not take into account the case where the hashtable has a single key-value pair. The function This is why in the test case @o-l-a-v highlighted, the property hashtable passed to So: Invoke-Formatter -ScriptDefinition "@{'Key'='Value';'key2'='value2'}" -Settings @{
Rules = @{
PSAlignAssignmentStatement = @{
Enable = $true
CheckHashtable = $true
}
}
} Results in: @{'Key'='Value';'key2'='value2'} @o-l-a-v - If you set the below, you won't see this behaviour - you'll also not get nice alignment of your hashtable property-value pairs though 😅. "powershell.codeFormatting.alignPropertyValuePairs": false I can do a small PR to add a check to see if there's just the 1 key-value pair, and if so, not to check it for violations - that should resolve this - assuming that's the desired behaviour. |
Great reasearch @liamjpeters. Your described behavior for a fix is what I'd want. |
Great details. Happy to support you in making a pull request, from my own experience I know though it's hard to write generic code without special cases like that and fixing them without breaking something else, we have got good test coverage though. |
Prerequisites
Summary
vscode-powershell inserts a space before an operator in some cases, even with:
PowerShell Version
Visual Studio Code Version
Extension Version
[email protected]
Steps to Reproduce
What it ends up looking like:
Notice it only adds a whitespace after
'Expression'
inSort-Object -Property
.Visuals
No response
Logs
No response
The text was updated successfully, but these errors were encountered: