Skip to content

Commit 7791597

Browse files
committed
chore: ✨ Update script analysis settings and improve task definitions
* Migrate `ScriptAnalyzerSettings.psd1` to `tests` directory and update paths. * Enhance task definitions in `psakeFile.ps1` for better readability and consistency. * Add new exclusion rule for `PSUseApprovedVerbs` in the script analysis settings.
1 parent a88c108 commit 7791597

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
"powershell.codeFormatting.addWhitespaceAroundPipe": true,
77
"powershell.codeFormatting.useCorrectCasing": true,
88
"powershell.codeFormatting.newLineAfterOpenBrace": true,
9-
"powershell.codeFormatting.alignPropertyValuePairs": true
9+
"powershell.codeFormatting.alignPropertyValuePairs": true,
10+
"powershell.scriptAnalysis.settingsPath": "tests/ScriptAnalyzerSettings.psd1"
1011
}

PowerShellBuild/ScriptAnalyzerSettings.psd1

Lines changed: 0 additions & 13 deletions
This file was deleted.

psakeFile.ps1

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
properties {
1+
Properties {
22
$settings = . ([IO.Path]::Combine($PSScriptRoot, 'build.settings.ps1'))
33
if ($galleryApiKey) {
44
$settings.PSGalleryApiKey = $galleryApiKey.GetNetworkCredential().password
55
}
66
}
77

8-
task default -depends Test
8+
Task default -depends Test
99

10-
task Init {
10+
Task Init {
1111
"STATUS: Testing with PowerShell $($settings.PSVersion)"
1212
'Build System Details:'
1313
Get-Item ENV:BH*
1414
} -description 'Initialize build environment'
1515

16-
task Test -Depends Init, Analyze, Pester -description 'Run test suite'
16+
Task Test -depends Init, Analyze, Pester -description 'Run test suite'
1717

18-
task Analyze -depends Build {
19-
$analysis = Invoke-ScriptAnalyzer -Path $settings.ModuleOutDir -Recurse -Verbose:$false -Settings ([IO.Path]::Combine($env:BHModulePath, 'ScriptAnalyzerSettings.psd1'))
20-
$errors = $analysis | Where-Object {$_.Severity -eq 'Error'}
21-
$warnings = $analysis | Where-Object {$_.Severity -eq 'Warning'}
18+
Task Analyze -depends Build {
19+
$analysis = Invoke-ScriptAnalyzer -Path $settings.ModuleOutDir -Recurse -Verbose:$false -Settings ([IO.Path]::Combine('tests', 'ScriptAnalyzerSettings.psd1'))
20+
$errors = $analysis | Where-Object { $_.Severity -eq 'Error' }
21+
$warnings = $analysis | Where-Object { $_.Severity -eq 'Warning' }
2222
if (@($errors).Count -gt 0) {
2323
Write-Error -Message 'One or more Script Analyzer errors were found. Build cannot continue!'
2424
$errors | Format-Table -AutoSize
@@ -30,25 +30,25 @@ task Analyze -depends Build {
3030
}
3131
} -description 'Run PSScriptAnalyzer'
3232

33-
task Pester -depends Build {
33+
Task Pester -depends Build {
3434
Remove-Module $settings.ProjectName -ErrorAction SilentlyContinue -Verbose:$false
3535

3636
$testResultsXml = [IO.Path]::Combine($settings.OutputDir, 'testResults.xml')
37-
$testResults = Invoke-Pester -Path $settings.Tests -Output Detailed -PassThru
37+
$testResults = Invoke-Pester -Path $settings.Tests -Output Detailed -PassThru
3838

3939
if ($testResults.FailedCount -gt 0) {
4040
$testResults | Format-List
4141
Write-Error -Message 'One or more Pester tests failed. Build cannot continue!'
4242
}
4343
} -description 'Run Pester tests'
4444

45-
task Clean -depends Init {
45+
Task Clean -depends Init {
4646
if (Test-Path -Path $settings.ModuleOutDir) {
4747
Remove-Item -Path $settings.ModuleOutDir -Recurse -Force -Verbose:$false
4848
}
4949
}
5050

51-
task Build -depends Init, Clean {
51+
Task Build -depends Init, Clean {
5252
New-Item -Path $settings.ModuleOutDir -ItemType Directory -Force > $null
5353
Copy-Item -Path "$($settings.SUT)/*" -Destination $settings.ModuleOutDir -Recurse
5454

@@ -59,7 +59,7 @@ task Build -depends Init, Clean {
5959
# & .\Build\Convert-PSAke.ps1 $psakePath | Out-File -Encoding UTF8 $ibPath
6060
}
6161

62-
task Publish -depends Test {
62+
Task Publish -depends Test {
6363
" Publishing version [$($settings.Manifest.ModuleVersion)] to PSGallery..."
6464
if ($settings.PSGalleryApiKey) {
6565
Publish-Module -Path $settings.ModuleOutDir -NuGetApiKey $settings.PSGalleryApiKey

tests/ScriptAnalyzerSettings.psd1

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
@{
2-
2+
ExcludeRules = @(
3+
'PSAvoidUsingWriteHost',
4+
'PSUseToExportFieldsInManifest',
5+
'PSUseDeclaredVarsMoreThanAssignments',
6+
# This throws a warning on Build verb, which is valid as of PSv6
7+
'PSUseApprovedVerbs'
8+
)
9+
Rules = @{
10+
# Don't trip on the task alias. It's by design
11+
PSAvoidUsingCmdletAliases = @{
12+
Whitelist = @('task')
13+
}
14+
}
315
}

0 commit comments

Comments
 (0)