From f5cedc18aa5363cf19ddfa3fc7167cb237d39d7b Mon Sep 17 00:00:00 2001 From: Jonathan Butler Date: Wed, 20 Nov 2024 16:10:51 -0500 Subject: [PATCH] Move psscriptanalzyer folder and associated PSSA config file, as the .github folder was not being loaded into the runner. --- .pre-commit-config.yaml | 27 +++++++++++++++++++++++ Hawk/tests/general/Test-PreCommitHook.ps1 | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..ed4d60f --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,27 @@ +repos: + - repo: local + hooks: + - id: powershell-script-analyzer + name: PowerShell Script Analyzer + entry: pwsh + args: + - -NoProfile + - -ExecutionPolicy + - Bypass + - -Command + - | + $ErrorActionPreference = 'Stop' + $settings = Join-Path (Get-Location) 'Hawk/tests/psscriptanalyzer/PSScriptAnalyzerSettings.psd1' + $files = git diff --cached --name-only --diff-filter=AM | Where-Object { $_ -match '\.(ps1|psm1|psd1)$' } + $hasErrors = $false + foreach ($file in $files) { + Write-Host "Analyzing $file..." + $results = Invoke-ScriptAnalyzer -Path $file -Settings $settings + if ($results) { + $results | Format-Table -AutoSize + $hasErrors = $true + } + } + if ($hasErrors) { exit 1 } + language: system + types: [powershell] diff --git a/Hawk/tests/general/Test-PreCommitHook.ps1 b/Hawk/tests/general/Test-PreCommitHook.ps1 index bb79a3d..ad4041d 100644 --- a/Hawk/tests/general/Test-PreCommitHook.ps1 +++ b/Hawk/tests/general/Test-PreCommitHook.ps1 @@ -5,7 +5,7 @@ # 3. Observe the PSScriptAnalyzer warnings/errors #region Good Code Examples - These will pass PSScriptAnalyzer -# add comment to testss +# add comment to testsss function Test-GoodFunction { [CmdletBinding()] param (