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

UseDeclaredVarsMoreThanAssignments for variables in Pester v5 #1605

Closed
rcdailey opened this issue Oct 26, 2020 · 2 comments
Closed

UseDeclaredVarsMoreThanAssignments for variables in Pester v5 #1605

rcdailey opened this issue Oct 26, 2020 · 2 comments

Comments

@rcdailey
Copy link

Using version v2020.6.0 of the PowerShell Extension for VS Code, I am getting a UseDeclaredVarsMoreThanAssignments in my Pester v5 test. The test case is this:

Describe "My Tests" {
    BeforeAll {
        $myVariable = 100
    }

    Context "My Context" {
        It "My Test" {
            $myVariable | Should -Not -Be $null
        }
    }
}

As seen in the screenshot below, I get a false positive warning on the assignment of $myVariable:

image

When I run this Pester test, it passes just fine. The variable $myVariable is actually used at line 8. However, I think due to the Pester framework, the analyzer isn't able to see that the variable is within scope. I'm honestly not sure what version of PSScriptAnalyzer is bundled in this VS Code extension.

The expected behavior is that this variable does not appear as an analysis warning in the context of Pester.

@bergmeister
Copy link
Collaborator

bergmeister commented Oct 26, 2020

This is a well known issue in this repo if you search through issues as Pester is a DSL that PSSA does not know about. Closing as a duplicate of #946

@rcdailey
Copy link
Author

rcdailey commented Oct 26, 2020

I did do quite a bit of searching, but all I had to go on was the keyword UseDeclaredVarsMoreThanAssignments, to which I found no results.

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