PowerShell / PowerShell/PSScriptAnalyzer
Rule request: PossibleArgumentWithOperatorConfusion
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 2.2k
- Forks
- 414
- Avg merge
- 13h 1m
- Merged PRs (30d)
- 2
Description
PowerShell has two parsing modes:
It is not always clear whenever PowerShell is in argument mode, as in:
if (&{ (1,2,3).Where{ $_ -eq 4 } } -isnot [int]) { Throw "The expression should return an integer"
For background information, see: Call operator (&{}) with no results doesn't type compare #24054
Yet from the argument name (and position and the operators) you could make a reasonable assumption that it probably concerns an operator instead.
For a (PowerShell based) rule prototype, see: https://github.com/iRon7/PSRules/blob/main/PossibleArgumentWithOperatorConfusion.psm1
Invoke-ScriptAnalyzer -CustomRulePath $RulePath -ScriptDefinition 'if (&{ (1,2,3).Where{ $_ -eq 4 } } -isnot [int]) { Throw "The expression should return an integer" }' | Select-Object *
Line : 1
Column : 5
Message : Possible argument with operator (-isnot) confusion.
Extent : &{ (1,2,3).Where{ $_ -eq 4 } } -isnot [int]
RuleName : PSPossibleArgumentWithOperatorConfusion
Severity : Warning
ScriptName :
ScriptPath :
RuleSuppressionID :
SuggestedCorrections : {(&{ (1,2,3).Where{ $_ -eq 4} }) -isnot [int]}
IsSuppressed : False
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
Start with the PowerShell rule prototype in PossibleArgumentWithOperatorConfusion.psm1 and review the linked PowerShell parsing issue for context. Compare the prototype's diagnostic, extent, and suggested correction with existing PSScriptAnalyzer rules; done means the requested confusion is detected with an appropriate warning and correction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100