Skip to content
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

Merged

Conversation

@bergmeister
Copy link
Collaborator

bergmeister commented Mar 26, 2018

PR Summary

Fixes #847

When an expression like $foo.bar(-$Var) is present, then the UseConsistentWhiteSpace 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 PR NA.

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • User facing documentation needed
  • Change is not breaking
  • Make sure you've added a new test if existing tests do not effectively test the code changed
  • This PR is ready to merge and is not work in progress
    • If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready
@bergmeister bergmeister self-assigned this Mar 26, 2018
@bergmeister bergmeister changed the title Formatter unary operator Tweak UseConsistenWhiteSpace formatting rule to exclude unary operator when being used as negative argument Mar 26, 2018
@bergmeister bergmeister changed the title Tweak UseConsistenWhiteSpace formatting rule to exclude unary operator when being used as negative argument Tweak UseConsistenWhiteSpace formatting rule to exclude first unary operator when being used in argument Mar 26, 2018
Copy link
Member

JamesWTruher left a comment

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" {

This comment has been minimized.

@JamesWTruher

JamesWTruher Mar 28, 2018 Member

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?

This comment has been minimized.

@bergmeister

bergmeister Mar 28, 2018 Author Collaborator

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.

@bergmeister bergmeister changed the title Tweak UseConsistenWhiteSpace formatting rule to exclude first unary operator when being used in argument Tweak UseConsistentWhiteSpace formatting rule to exclude first unary operator when being used in argument Mar 28, 2018
@bergmeister bergmeister merged commit 00c4787 into PowerShell:development Mar 28, 2018
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
license/cla All CLA requirements met.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

2 participants
You can’t perform that action at this time.