PowerShell / PowerShell/PSScriptAnalyzer
Rule request: PossibleArgumentWithOperatorConfusion
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- C#
- Sterne
- 2.2k
- Forks
- 414
- Ø Merge
- 13 Std. 1 Min.
- Gemergte PRs (30 T.)
- 2
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit dem PowerShell-Regelprototyp in PossibleArgumentWithOperatorConfusion.psm1 und sieh dir zur Kontextualisierung das verknüpfte PowerShell-Parsing-Issue an. Vergleiche die Diagnose, den Gültigkeitsbereich und die vorgeschlagene Korrektur des Prototyps mit bestehenden PSScriptAnalyzer-Regeln; als abgeschlossen gilt die Aufgabe, wenn die angeforderte Verwechslung mit einer angemessenen Warnung und Korrektur erkannt wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- powershell
- Bereich
- tooling
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100