PowerShell / PowerShell/PSScriptAnalyzer

`Invoke-ScriptAnalyzer` parameterset ambiguity

Abierto
#2,130 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
C#
Estrellas
2.2k
Forks
414
Merge medio
13 h 1 min
PR fusionados (30 d)
2

Descripción

Summary

Both the -Path and -ScriptDefinition parameters of Invoke-ScriptAnalyzer are [string] parameters. Both accept ValueFromPipeline and both are declared as Position=0. While they exist in different parameter sets (each with two variants), there is no unique parameter in either set that would allow PowerShell to disambiguate and select the intended parameter set during binding.

As a result, the default parameter set (Path_SuppressedOnly) is always chosen. Any string passed down the pipeline (by value) or as a positional argument is bound to the Path parameter. This means that ScriptDefinition's Position=0 and pipeline (by value) binding declarations are effectively unreachable - any positional or pipeline string will always be bound to Path.

This isn't a bug, but is a design issue: the ScriptDefinition parameter advertises pipeline (by value) and positional binding, but there is no way for users to actually use these features due to parameter set ambiguity.

I propose removing ValueFromPipeline = true and Position = 0 from ScriptDefinition. This isn't a breaking change as they can't currently be used.

ValueFromPipelineByPropertyName is fine - the below works:

[PSCustomObject]@{ScriptDefinition = '$Var = 1'} | Invoke-ScriptAnalyzer

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.4.11
PSEdition                      Core
GitCommitId                    7.4.11
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }

1.24.0

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza por las declaraciones de parámetros de Invoke-ScriptAnalyzer e inspecciona los conjuntos de parámetros Path y ScriptDefinition, incluidos sus metadatos de enlace posicional y de enlace desde la canalización. La tarea estará terminada cuando ScriptDefinition deje de anunciar los enlaces posicionales o de canalización por valor inalcanzables, mientras el enlace por nombre de propiedad siga estando disponible; verifica el comportamiento resultante del comando con los ejemplos del issue.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
powershell
Área
cli
Tipo de issue
Refactorización
Dificultad
2/5
Tiempo estimado
1-3 horas
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.