FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Tweak UseConsistentWhiteSpace formatting rule to exclude first unary operator when being used in argument by bergmeister · Pull Request #949 · PowerShell/PSScriptAnalyzer · GitHub

Tweak UseConsistentWhiteSpace formatting rule to exclude first unary operator when being used in argument - #949

Merged
Christoph Bergmeister (bergmeister) merged 7 commits into
PowerShell:developmentfrom
bergmeister:formatter_unaryOperator
Mar 28, 2018
Merged

Tweak UseConsistentWhiteSpace formatting rule to exclude first unary operator when being used in argument#949
Christoph Bergmeister (bergmeister) merged 7 commits into
PowerShell:developmentfrom
bergmeister:formatter_unaryOperator

Conversation

Christoph Bergmeister (bergmeister) commented Mar 26, 2018
edited
Loading

Copy link
Copy Markdown
Collaborator

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

Christoph 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
Christoph 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
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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?

Christoph Bergmeister (bergmeister) Mar 28, 2018
edited
Loading

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Christoph 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
Christoph Bergmeister (bergmeister) merged commit 00c4787 into PowerShell:development Mar 28, 2018
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Formatter adds spaces around a hyphen, but only if it is followed by a variable

2 participants


Back | FazBrowse Home | New Git URL