Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSReviewUnusedParameter not finding script-param inside function scope (implicit and explicit) #2017

Closed
LukasGelke opened this issue Aug 2, 2024 · 2 comments

Comments

@LukasGelke
Copy link

Steps to reproduce

implicit:

param(
  [string]$name
)

function Invoke-Main
{
  "$name"
  "$script:name"
}

Invoke-Main
> .\issue.ps1 "abc"
abc
abc

explicit:

param(
  [string]$name
)

function Invoke-Main($name)
{
  "$name"
  "$script:name"
}

Invoke-Main "123"
> .\issue.ps1 "abc"
123
abc

both scripts work as expected.

Expected behavior

no PSReviewUnusedParameter in either case.
(Perhaps some "ambiguous" or "shadowing" warning/info in the second case, but that's not the point here)

Actual behavior

(both cases)

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSReviewUnusedParameter             Warning      issue.ps1  2     The parameter 'name' has been declared but not used.

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      7.4.4
PSEdition                      Core
GitCommitId                    7.4.4
OS                             Microsoft Windows 10.0.19045
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.22.0

Notes

We have several scripts that work similar to this (script-param used in "script-internal" functions) due to try-finally, try.catch, logging, or params like Endpoint-URI, Database-Name/Address,... that would not change during script execution. They are scripts, intended (and used as such) to be ran on their own, not modules. It would be horrible to read an maintain, if we had to explicitly pass all script-params to every relevant function again.
But it would still be ok if every reference had to use the $script: syntax, for strictness/debugging/maintainability/etc.

@SydneyhSmith
Copy link
Collaborator

Thanks for the issue this looks like a duplicate of #1472

Copy link
Contributor

This issue has been marked as duplicate and has not had any activity for 1 day. It will be closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants