Skip to content

Return variable reported as assigned but never used #1687

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

Closed
lovettchris opened this issue Jun 15, 2021 · 1 comment
Closed

Return variable reported as assigned but never used #1687

lovettchris opened this issue Jun 15, 2021 · 1 comment

Comments

@lovettchris
Copy link

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

function FindProgram($name) {
    $result = $null
    $path = $ENV:PATH.split([System.IO.Path]::PathSeparator) | ForEach-Object {
        $test = Join-Path -Path $_ -ChildPath $name
        if ($IsWindows) {
            $test = $test + ".exe"
        }
        if (Test-Path -Path $test) {
            $result = "$_/$name"
        }
    }
    return $result
}

Expected behavior

should be now PSScriptAnalyzer warnings in this code.

Actual behavior

image

The variable 'result' is assigned but never used.PSScriptAnalyzer(PSUseDeclaredVarsMoreThanAssignments)

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Microsoft Windows 10.0.19043
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.19.1
@ghost ghost added the Needs: Triage 🔍 label Jun 15, 2021
@rjmholt
Copy link
Contributor

rjmholt commented Jul 6, 2021

Duplicate of #1163

@rjmholt rjmholt marked this as a duplicate of #1163 Jul 6, 2021
@rjmholt rjmholt closed this as completed Jul 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants