Skip to content

Commit

Permalink
Test good workflow once more.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnybottles committed Nov 26, 2024
1 parent ec01690 commit d08367e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 32 deletions.
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 }
9 changes: 4 additions & 5 deletions Hawk/tests/general/Test-PreCommitHook.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ function Test-AdvancedFunction {
#region Bad Code Examples - Uncomment to test PSScriptAnalyzer
# NOTE: The following code is intentionally written with issues to demonstrate PSScriptAnalyzer rules


<#
# Bad function - Multiple issues
function test-badfunction {
# Wrong capitalization
function test-badfunction { # Wrong capitalization
param([string]$param1) # Missing CmdletBinding
$Global:badVariable = $param1 # Using global variable
Expand All @@ -78,8 +77,8 @@ function Test-BadValidation {
}
# Aliases and positional parameters
dir C:\ | where { $_.Length -gt 1000 } # Using aliases instead of full cmdlet names

dir C:\ | where {$_.Length -gt 1000} # Using aliases instead of full cmdlet names
#>
#endregion

#region Testing Instructions
Expand Down

0 comments on commit d08367e

Please sign in to comment.