Skip to content

Commit c76fdf7

Browse files
🩹 [Patch]: Refactor PSScriptAnalyzer test results handling for improved variable scope and clarity
1 parent 92b4b68 commit c76fdf7

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

‎scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,12 @@ Describe 'PSScriptAnalyzer' {
7878
PSScriptRoot = $PSScriptRoot
7979
GITHUB_WORKSPACE = $env:GITHUB_WORKSPACE
8080
}
81+
$Path = Resolve-Path -Path $Path | Select-Object -ExpandProperty Path
8182
LogGroup "Invoke-ScriptAnalyzer -Path [$Path] -Settings [$relativeSettingsFilePath]" {
82-
$script:testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose
83+
$testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose
8384
}
84-
LogGroup "TestResults [$($script:testResults.Count)]" {
85-
$script:testResults | ForEach-Object {
85+
LogGroup "TestResults [$($testResults.Count)]" {
86+
$testResults | ForEach-Object {
8687
$_ | Format-List | Out-String -Stream | ForEach-Object {
8788
Write-Verbose $_ -Verbose
8889
}
@@ -95,7 +96,7 @@ Describe 'PSScriptAnalyzer' {
9596
foreach ($rule in $rules | Where-Object -Property Severity -EQ $Severety) {
9697
It "$($rule.CommonName) ($($rule.RuleName))" -Skip:$rule.Skip -ForEach @{ Rule = $rule } {
9798
$issues = [Collections.Generic.List[string]]::new()
98-
$script:testResults | Where-Object -Property RuleName -EQ $Rule.RuleName | ForEach-Object {
99+
$testResults | Where-Object { $_.RuleName -eq $Rule.RuleName } | ForEach-Object {
99100
$relativePath = $_.ScriptPath.Replace($Path, '').Trim('\').Trim('/')
100101
$issues.Add(([Environment]::NewLine + " - $relativePath`:L$($_.Line):C$($_.Column)"))
101102
}

0 commit comments

Comments
 (0)