-
Notifications
You must be signed in to change notification settings - Fork 389
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
PSScriptAnalyzer marks unused param but it is used in the script #1924
Comments
Well, there's already #1923 But I came here for the same issue, to be honest, I've encountered the same problem. |
yes, this is an known issue in script analyzer because of the "apparent" scope created by the scriptblock in param(
[Parameter(Mandatory)] [string]$acrName,
[Parameter(Mandatory)] [string]$ipAddress
)
$networkRuleExists = $false
$existingNetworkRules = ./Get-AcrNetworkRule -acrName $acrName
foreach($rule in $existingNetworkRules.ipRules) {
if($rule.ipAddressOrRange -eq $ipAddress) {
Write-Output "NetworkRule already exists.";
$networkRuleExists = $true;
if(!$networkRuleExists)
{
az acr network-rule add --name $acrName --ip-address $ipAddress
if($LASTEXITCODE -ne 0){Throw "az acr network-rule add returned a $LASTEXITCODE exit code."}
Start-Sleep -Seconds 120
}
return
}
} |
@JamesWTruher Okay, so maybe I am actually referring to a slightly different issue here? Because in my case, it is definitely not related to the scriptblock by As far as I understand it, it is still related to the scope here, though. I get that the Anyway, here's a simple example to reproduce: <#
.SYNOPSIS
Minimal testcase for demonstration purposes
#>
param(
[Parameter(Position=0)]
[string] $ExampleInput = "I am just a simple DEMO string",
[switch] $Lower,
[switch] $Upper,
[switch] $Variant,
[switch] $DemoSwitch
)
function LocalFunc ([string] $In) {
if ($DemoSwitch) {
return $In.Replace('string', 'string, DemoSwitch is SET! SUCCESS!')
} else {
return $In.Replace('string', 'string, DemoSwitch is NOT SET! ("default" operation)')
}
}
if ($Variant) {
Write-Output (LocalFunc -In $ExampleInput)
}
elseif ($Lower) {
Write-Output $ExampleInput.ToLower()
}
elseif ($Upper) {
Write-Output $ExampleInput.ToUpper()
}
else {
Write-Output $ExampleInput
} PSScriptAnalyzer complains as following:
But the script itself is clearly working as intended. |
This issue has been marked as duplicate and has not had any activity for 1 day. It will be closed for housekeeping purposes. |
This issue has been marked as duplicate and has not had any activity for 1 day. It will be closed for housekeeping purposes. |
@Hrxn latest example is still a scope issue because that LocalFunc creates a scope/scriptblock |
True, but this issue is closed now anyways. The confusion did originally stem from a comment in another closed duplicate issue (#1923) on this very same thing, stating that it's caused by "how PSSA handles scoping for the Where-Object script block". So, the correct issue for this is now #1472, it seems. |
Before submitting a bug report:
Steps to reproduce
Hello everyone, I am a newbie to PSScriptAnalyzer. I run into a little issue. I run PSScriptAnalyzer to one of my script and here is the warning I received "The parameter "ipAddress" has been declared but not used". I wonder that can this warning consider as false positive since my script did use this parameter by passing it to another script. Any response would be appreciated!
Expected behavior
Actual behavior
If an unexpected error was thrown then please report the full error details using e.g.
$error[0] | Select-Object *
Environment data
The text was updated successfully, but these errors were encountered: