Skip to content

Commit bf472e4

Browse files
author
Kapil Borle
committed
Add test case for UseDeclaredVarsMoreThanAssignment
1 parent ee4cd62 commit bf472e4

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Tests/Rules/UseDeclaredVarsMoreThanAssignments.tests.ps1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@ Describe "UseDeclaredVarsMoreThanAssignments" {
1515
$violations[1].Message | Should Match $violationMessage
1616
}
1717

18+
It "flags the variable in the correct scope" {
19+
$target = @'
20+
function MyFunc1() {
21+
$a = 1
22+
$b = 1
23+
$a + $b
24+
}
25+
26+
function MyFunc2() {
27+
$a = 1
28+
$b = 1
29+
$a + $a
30+
}
31+
'@
32+
$local:violations = Invoke-ScriptAnalyzer -ScriptDefinition $target -IncludeRule $violationName
33+
$local:violations.Count | Should Be 1
34+
}
1835
}
1936

2037
Context "When there are no violations" {

0 commit comments

Comments
 (0)