PSScriptAnalyzer
PSScriptAnalyzer copied to clipboard
UseConsistentWhitespace.CheckOperator: Add unary operators that start with a dash (-split, -join, -not, -bnot, isplit, csplit)
PR Summary
Related: #1239
In order to enable formatting corrections of this kind: $a-join$b
--> $a -join $b
or reducing too much whitespace but also -split$a --> -split $a
with the added code as existing code for operators assumes that something precedes it.
The reason for adding the check that the unary operator starts with a dash is is to exclude things like $a++
or !$a
where we do not want a whitespace character separation by default
PR Checklist
- [x] PR has a meaningful title
- Use the present tense and imperative mood when describing your changes
- [x] Summarized changes
- [x] Change is not breaking
- [x] Make sure all
.cs
,.ps1
and.psm1
files have the correct copyright header - [x] Make sure you've added a new test if existing tests do not effectively test the code changed and/or updated documentation
- [x] 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.
- If the PR is work in progress, please add the prefix
I tried this code out and noticed a couple things.
Checking that the operator starts with a dash introduces the following undesirable behavior: --$counter
is changed to -- $counter
. Also $counter--
is changed to $counter --
Unary operator -not
does not get spacing if it follows a parenthesis such as if (-not$SomeVariable)
.
Converting to draft to resolve the various PRs