PowerShell / PowerShell/PSScriptAnalyzer
Enhance PSUseConsistentWhiteSpace to exclude more special cases when using unary operators
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 2.2k
- Forks
- 414
- Avg merge
- 13h 1m
- Merged PRs (30d)
- 2
Description
Found when discussing PR #949 , which already tweaked PSUseConsistentWhiteSpace when using unary operators inside parenthesis.
This adds another special case where the rule should be excluded. The community is welcome to provide more cases that need to be treated specially.
Steps to reproduce
Invoke-Formatter -ScriptDefinition '$r = $a -lt -$var'
Expected behavior
$r = $a -lt -$var
Actual behavior
$r = $a -lt - $var
Environment data
This applies also to the latest version of the development branch.
> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.16299.251
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.16299.251
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.16.1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with Invoke-Formatter and the PSUseConsistentWhiteSpace rule using the script definition shown. Trace the formatter behavior for the unary operator expression and verify that the completed change preserves $r = $a -lt -$var without inserting a space between the unary minus and $var.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, powershell
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100