-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec01690
commit d08367e
Showing
2 changed files
with
22 additions
and
32 deletions.
There are no files selected for viewing
45 changes: 18 additions & 27 deletions
45
Hawk/internal/scripts/pre_commit_hook_scripts/Invoke-PowerShellScriptAnalyzer.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,25 @@ | ||
if ($MyInvocation.ScriptName -eq (Join-Path $PSScriptRoot 'Invoke-PowerShellScriptAnalyzer.ps1')) { | ||
$excludedFiles = @( | ||
'C:\Users\xxbut\code\hawk\Hawk\tests\general\Test-PreCommitHook.ps1' | ||
) | ||
$ErrorActionPreference = 'Stop' | ||
$settings = Join-Path (Get-Location) 'Hawk/internal/configurations/PSScriptAnalyzerSettings.psd1' | ||
|
||
$files = git diff --cached --name-only --diff-filter=AM | Where-Object { $_ -match '\.(ps1|psm1|psd1)$' } | ||
$hasErrors = $false | ||
# Define the list of files to exclude | ||
$excludedFiles = @( | ||
'none' | ||
) | ||
|
||
foreach ($file in $files) { | ||
if ($excludedFiles -contains $file) { | ||
Write-Output "Skipping analysis for excluded file: $file" | ||
} | ||
else { | ||
Write-Output "Analyzing $file..." | ||
$results = Invoke-ScriptAnalyzer -Path $file -Settings $settings | ||
if ($results) { | ||
$results | Format-Table -AutoSize | ||
$hasErrors = $true | ||
} | ||
} | ||
} | ||
$files = git diff --cached --name-only --diff-filter=AM | Where-Object { $_ -match '\.(ps1|psm1|psd1)$' } | ||
$hasErrors = $false | ||
|
||
if ($hasErrors) { | ||
Write-Output "PSScriptAnalyzer found errors. Exiting with error code 1." | ||
exit 1 | ||
foreach ($file in $files) { | ||
if ($excludedFiles -notcontains $file) { | ||
Write-Output "Analyzing $file..." | ||
$results = Invoke-ScriptAnalyzer -Path $file -Settings $settings | ||
if ($results) { | ||
$results | Format-Table -AutoSize | ||
$hasErrors = $true | ||
} | ||
} | ||
else { | ||
Write-Output "No PSScriptAnalyzer issues found. Exiting with code 0." | ||
exit 0 | ||
Write-Output "Skipping analysis for excluded file: $file" | ||
} | ||
} | ||
else { | ||
# Original script content | ||
} | ||
if ($hasErrors) { exit 1 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters