PowerShell / PowerShell/PSScriptAnalyzer

Rule Idea: Pipeline Type Checking against Output

Offen
#1,760 3 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Issue - Discussion
Vorherrschende Sprache
C#
Sterne
2.2k
Forks
414
Ø Merge
13 Std. 1 Min.
Gemergte PRs (30 T.)
2

Beschreibung

This is just a spitball idea to contribute feedback if it is maybe feasible, I might consider attempting a PR

Problem

Often when writing a pipeline you may pipe an incompatible type, and you won't find out until runtime.

Proposed solution

If the output type of a function can be explicitly determined by:

  1. Use the .OUTPUT comment based help section to define the output type of a function
  2. Take all explicit return keywords that explicitly cast to a type e.g. return [MyType]@{} or can be simply derived from a typed variable e.g. $f = [MyType]::new();return $f

And the function being called either to or from meets the following criteria:

  1. Has strictly typed non-primitive parameter or ValueFromPipeline

Then we should be able to safely issue a warning or error stating something like "MyFunction expected [MyType] but is receiving [WrongType] via the pipeline" as a static analysis.

#Issues

  1. Easily castable types like string we have to exclude, they will basically always match
  2. Probably should support/detect explicit casts or interfaces

Prior Art

How JSDoc can be used to test for type safety in normally-untyped javascript.

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

Beginne mit der Prüfung der im Issue beschriebenen vorgeschlagenen Quellen für Ausgabetypen, Prüfungen der Pipeline-Parameter, Casting-Ausnahmen und des bisherigen JSDoc. Lege vor der Implementierung den Einstiegspunkt und den Umfang des Analyzers fest; als erledigt gilt, wenn ein festgelegter Ansatz inkompatible Pipeline-Typen erkennen kann und dabei sicher castbare Werte ausschließt sowie explizite Casts oder Interfaces behandelt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
powershell
Bereich
tooling
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

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