PowerShell / PowerShell/PSScriptAnalyzer

Private parameters are reported as unused

Aperta
#1,891 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Issue - Enhancement Up-for-Grabs
Lingua principale
C#
Stelle
2.2k
Fork
414
Merge medio
13h 1m
PR unite (30g)
2

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia eseguendo Invoke-ScriptAnalyzer sulla riproduzione PowerShell ed esamina l'implementazione e la copertura della regola PSReviewUnusedParameter. Conferma che il parametro privato e il suo uso finale siano riconosciuti come la stessa variabile; il lavoro è completato quando la riproduzione non produce alcun avviso di parametro inutilizzato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
powershell
Ambito
tooling
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.