-
Notifications
You must be signed in to change notification settings - Fork 393
Tweak UseConsistentWhiteSpace formatting rule to exclude first unary operator when being used in argument #949
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
Tweak UseConsistentWhiteSpace formatting rule to exclude first unary operator when being used in argument #949
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this is definitely improving the current experience, this isn't a blocking comment or one that requires a change, but I think this can go a bit further.
Invoke-Formatter '$foo.bar(-$a)' -Settings CodeFormatting | Should -Be $script | ||
} | ||
|
||
It "Should expand unary operators when not being used as a single negative argument" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm not sure it's not just parens where this be applied. Take the following:
PS> Invoke-Formatter -ScriptDefinition '$r = $a -lt -$var'
$r = $a -lt - $var
shouldn't that be $r = $a -lt -$var
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you. I extracted this into the new issue #950 to separate concerns and finish this PR. I am sure there are other special cases as well but I guess the best approach is to find them one by one and find heuristics to detect each case I suppose.
…nalyzer into formatter_unaryOperator
…ter/PSScriptAnalyzer into formatter_unaryOperator
PR Summary
Fixes #847
When an expression like
$foo.bar(-$Var)
is present, then theUseConsistentWhiteSpace
should not expand spaces around this expression.This works by checking if the
-
operator is an unary operator, is preceded by an open parenthesis and followed by a variable.PR Checklist
Note: Tick the boxes below that apply to this pull request by putting an
x
between the square brackets. Please mark anything not applicable to this PRNA
.WIP:
to the beginning of the title and remove the prefix when the PR is ready