PowerShell / PowerShell/PSScriptAnalyzer

Private parameters are reported as unused

Abierto
#1,891 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Issue - Enhancement Up-for-Grabs
Lenguaje dominante
C#
Estrellas
2.2k
Forks
414
Merge medio
13 h 1 min
PR fusionados (30 d)
2

Descripción

Before submitting a bug report:

  • Make sure you are able to repro it on the latest released version
  • Perform a quick search for existing issues to check if this bug has already been reported

Steps to reproduce

Run the analyzer against this script.

Param (
    [String] $private:var1
)

function Test-Second
{
    # $var1 is not accessible because it was private to the script.
    Write-Information -InformationAction "continue" "From script: $var1"

    # $var2 is not private to the calling function so we can access it.
    Write-Information -InformationAction "continue" "From caller: $var2"
}

function Test-NotGlobal
{
    Param (
        [String] $var2
    )
    $a = $var1 + " " + $var2
    Write-Information -InformationAction "continue" "Concatenation: $a"
    Test-Second
}

Test-NotGlobal $var1

Expected behavior

Expect no errors because $private:var1 and the use in the last line of $var1 are the same variable and $var1 is private to the script, as required.


Actual behavior

PS C:\Users\pauldsmith> Invoke-ScriptAnalyzer c:\temp\gvar.ps1

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSReviewUnusedParameter             Warning      gvar.ps1   2     The parameter 'private:var1' has been declared but not
                                                                  used.


PS C:\Users\pauldsmith>

If an unexpected error was thrown then please report the full error details using e.g. $error[0] | Select-Object *

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.22621.963
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.22621.963
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

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

1.21.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 ejecutando Invoke-ScriptAnalyzer en la reproducción de PowerShell e inspecciona la implementación y la cobertura de la regla PSReviewUnusedParameter. Confirma que el parámetro privado y su uso final se reconocen como la misma variable; se considera completado cuando la reproducción no produce ninguna advertencia de parámetro no utilizado.

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

Evaluación

Stack tecnológico
powershell
Área
tooling
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.