PowerShell / PowerShell/PSScriptAnalyzer

Rule request: AvoidUsingOutNull

Offen
#2,110 0 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

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

Summary of the new feature

I want PSScriptAnalyzer to flag uses of Out-Null for output suppression so that I can maintain consistent code style and potentially gain minor performance improvements.

Currently, many PowerShell scripts use | Out-Null to suppress command output, but there are alternative approaches like [void], > $null, or assignment to $null that are stylistically preferred by many developers. While the performance difference is minimal, having a consistent approach to output suppression improves code readability and maintainability.

Proposed technical implementation details (optional)

  • Rule Name: AvoidUsingOutNull
  • Severity: Information (since this is primarily a style preference)
  • Category: Style
  • Detection: Flag any pipeline that ends with | Out-Null
  • Suggested alternatives:
    • [void](command)
    • command > $null
    • $null = command
  • Example violation: Get-Process | Out-Null
  • Example fix: [void](Get-Process) or Get-Process > $null

The rule should provide informational messages suggesting these alternatives while acknowledging that this is primarily a stylistic choice rather than a critical performance issue.

What is the latest version of PSScriptAnalyzer at the point of writing

1.24.0

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Finde vergleichbare PSScriptAnalyzer-Regeln und deren Tests, und untersuche anschließend, wie Regelnamen, Schweregrade, Kategorien, Diagnosen und Pipeline-Muster dargestellt werden. Erledigt ist die Aufgabe, wenn Pipelines, die mit Out-Null enden, eine informative Style-Diagnose mit vorgeschlagenen Alternativen erzeugen, während andere Formen der Ausgab Unterdrückung unbeeinflusst bleiben.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
csharp, powershell
Bereich
tooling
Issue-Typ
Feature
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.