-
Notifications
You must be signed in to change notification settings - Fork 389
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
unary operators not getting spaced #1239
Comments
Interesting, vscode is already using pssa 1.18.0, it ships a backup version of pssa in case it is not installed. |
You can check your version in the integrated console with The latest extension ships with 1.18.0. |
Sorry that I forgot to come back to this. Can you give specific examples using |
A couple examples invoke-formatter {-not$a-1}
'-not$a - 1' # spaces added around '-' but not between '-not' and '$a'
# '-not $a - 1' would be the desired outcome
invoke-formatter {-not $a - 1} # double spaced
'-not $a - 1' # spaces were trimmed up around '-' but not between '-not' and '$a'
# '-not $a - 1' would be the desired outcome
invoke-formatter {-split"hello"}
'-split"hello"' # no spacing between operator
# '-split "hello"' would be desired outcome
invoke-formatter {"hello"-split"`n"} # reference a binary operator of the same name
'"hello" -split "`n"' # is formatted as expected. additional scenarios: invoke-formatter {- $a - 1} # double spaced
'- $a - 1' # spaces were trimmed around 'minus' but not between 'negate' and '$a'
# '-$a - 1' would be the expected outcome
invoke-formatter {++ $a - 1} # double spaced
'++ $a - 1' # spaces were trimmed around 'minus' but not between 'increment' and '$a'
# '++$a - 1' would be the expected outcome
invoke-formatter {$a ++} # double spaced
# no change occurs, '$a++' would be the expected outcome |
With PSSA 1.18.1, Also, I find sometimes VS Code In this case I have hello |
hello some more tasks | hello some more
some more tasks |
maybe more
-split$a This is at the end of a file, the file is dirty, and I selected this text right up to the end of the file. There is no blank line past the |
I see I am getting different results between different methods … which explains why my results in VS Code are different. If I use |
I have run into this issue as well in version 1.19.1. Actually as msftrncs discovered, there are really multiple issues related to whitespace around unary operators. Problem 1: Unary operators such as
|
@bergmeister , is it possible to get traction on this from the core team? This issues is well over a year old. |
I believe @bergmeister is fairly busy in other areas at the moment (he gives his time freely to the PSScriptAnalyzer project), and the PowerShell team members who have PSScriptAnalyzer in their portfolio are currently spread thin across various other projects. PSScriptAnalyzer is always accepting PRs though. |
Thanks for the reminder around this issue. Age of an issue does not matter as much as urgency versus priority matters, i.e. if something is a bug or a missing feature and what the impact is. In this case, most cases are mainly a missing feature and there are a couple of other things as well where PSSA formatter does not help with spaces such as e.g.
|
I opened PR #1602, which adds simple functionality by re-using an existing rule logic for binary and assignment operators that now allows the following scenarios to work for unary operators starting with a dash $a-join$b --> $a -join $b $a -join $b --> $a -join $b -join$a --> -join $a How would you feel about closing this issue after that PR but open 1 new issue for the cases where an additional unwanted space is inserted after a negation - or before a binary operator as in the given example |
I am going to start by saying after looking at this issue for a while I think it would be worth changing the implementation of I suppose, to in order to make this issue just about one thing, I personally would consider it solved if
I can't conjure up examples of this in my head very well. I wouldn't think it would affect unary operators as much as binary ones (since there is only one operand and it is at usually on the right side) but I realize the code I look at doesn't cover all scenarios. If necessary, I suppose it could be a separate option to fix whitespace around unary operators. However, the current behavior of I think that inserting an extra space on the wrong side of a unary operator is also a bug, but I suppose that could be a separate issue if necessary. I agree that enforcing no space around prefix/postfix probably should be a separate issue and probably optional. |
Following up from #847 / #948,
PSSA 1.18.0 Invoke-Formatter no longer inserts a space between letter/word based unary operators, such as
-split
or-not
.If I use the format selection command in VS Code I get a different result, but I am suspecting that VSCode / PowerShell Extension is still using PSSA 1.17.x.
I suspect this is from trying not to space out the unary 'negate' or 'positive' operators. Probably a simple idea might be to look at the length of the operator, length > 2 should be spaced.
The text was updated successfully, but these errors were encountered: