Skip to content

Commit 65f7758

Browse files
🪲 [Fix]: When an issue is found, output script path (#10)
## Description This pull request includes a small change to the `PSScriptAnalyzer.Tests.ps1` file. The change modifies the way script paths are handled in test results to improve the readability of issue locations. * [`scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1`](diffhunk://#diff-506030604c5eac4d6d266aa14f0e8cf3a8121425c1f579406e3a003d5b091ac9L109-R110): Changed the script path handling to use `relativeScriptPath` instead of `relativePath` for better readability in issue locations. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [x] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent bf39b54 commit 65f7758

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,8 @@ Describe 'PSScriptAnalyzer' {
9292
$testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose
9393
}
9494
LogGroup "TestResults [$($testResults.Count)]" {
95-
$testResults | ForEach-Object {
96-
$_ | Format-List | Out-String -Stream | ForEach-Object {
97-
Write-Verbose $_ -Verbose
98-
}
95+
$testResults | Select-Object -Property * | Format-List | Out-String -Stream | ForEach-Object {
96+
Write-Verbose $_ -Verbose
9997
}
10098
}
10199
}
@@ -106,7 +104,14 @@ Describe 'PSScriptAnalyzer' {
106104
It "$($rule.CommonName) ($($rule.RuleName))" -Skip:$rule.Skip -ForEach @{ Rule = $rule } {
107105
$issues = [Collections.Generic.List[string]]::new()
108106
$testResults | Where-Object { $_.RuleName -eq $Rule.RuleName } | ForEach-Object {
109-
$issues.Add(([Environment]::NewLine + " - $relativePath`:L$($_.Line):C$($_.Column)"))
107+
$relativeScriptPath = if ($_.ScriptPath.StartsWith($PSScriptRoot)) {
108+
$_.ScriptPath.Replace($PSScriptRoot, 'Action:').Trim('\').Trim('/')
109+
} elseif ($_.ScriptPath.StartsWith($env:GITHUB_WORKSPACE)) {
110+
$_.ScriptPath.Replace($env:GITHUB_WORKSPACE, 'Workspace:').Trim('\').Trim('/')
111+
} else {
112+
$_.ScriptPath
113+
}
114+
$issues.Add(([Environment]::NewLine + " - $relativeScriptPath`:L$($_.Line):C$($_.Column)"))
110115
}
111116
$issues -join '' | Should -BeNullOrEmpty -Because $rule.Description
112117
}

0 commit comments

Comments
 (0)