Skip to content

Commit b0b007b

Browse files
tablackburnclaude
andcommitted
style: drop named parameters from single-argument calls in test scaffolding
Apply the scoped named-parameter rule to the template's test scaffolding: name parameters only on calls that pass two or more arguments; single-argument calls stay positional. Reverts over-naming such as `Test-Path -Path $path` and `Get-Module -Name $name` back to `Test-Path $path` / `Get-Module $name` across the Help/Manifest/Meta tests, MetaFixers, and the Unit test templates. Calls that genuinely pass two or more value arguments keep their names (`Join-Path -Path -ChildPath`, `Get-Content -Path -Encoding -Raw`, `Get-Command -Name -CommandType`), as does `Test-Path -LiteralPath` whose positional slot binds to -Path and would change wildcard semantics. This is the canonical-source fix for the over-naming that propagated into the consumer test-scaffolding PRs; pairs with the rule scoping in tablackburn/ai-agent-instruction-modules#25. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 982286a commit b0b007b

7 files changed

Lines changed: 46 additions & 45 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ own `CHANGELOG.md` (generated from `CHANGELOG.template.md` during init).
1818
### Changed
1919

2020
- Renamed required PowerShell Gallery publish secret `PS_GALLERY_KEY``PSGALLERY_API_KEY` so the secret name matches the env var name PowerShellBuild reads (eliminating the previous mapping caveat). New modules created from the template after this change pick up the new name automatically. **Migration for existing modules:** create a new `PSGALLERY_API_KEY` repo secret with the same value, update `.github/workflows/PublishModuleToPowerShellGallery.yaml` to reference `secrets.PSGALLERY_API_KEY`, then delete the old `PS_GALLERY_KEY` secret.
21+
- Test scaffolding (`tests/Help.tests.ps1`, `tests/Manifest.tests.ps1`, `tests/Meta.tests.ps1`, `tests/MetaFixers.psm1`, and the `tests/Unit/` templates) no longer names parameters on single-argument calls (e.g. `Test-Path $path`, `Get-Module $name`), matching the scoped named-parameter rule — name parameters only when a call passes two or more arguments. Calls with two or more value arguments (`Join-Path`, `Get-Content … -Encoding … -Raw`, `Get-Command -Name … -CommandType …`) and `Test-Path -LiteralPath` keep their names.
2122

2223
## [2026.04.29] - 2026-04-29
2324

tests/Help.tests.ps1

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ BeforeDiscovery {
4242
param ($Parameters)
4343
$commonParameters = [System.Management.Automation.PSCmdlet]::CommonParameters +
4444
[System.Management.Automation.PSCmdlet]::OptionalCommonParameters
45-
$Parameters | Where-Object { $_.Name -notin $commonParameters -and $_.IsDynamic -eq $false } | Sort-Object -Property 'Name' -Unique
45+
$Parameters | Where-Object { $_.Name -notin $commonParameters -and $_.IsDynamic -eq $false } | Sort-Object 'Name' -Unique
4646
}
4747

4848
# Check if the BHBuildOutput environment variable exists to determine if this test is running in a psake
@@ -57,9 +57,9 @@ BeforeDiscovery {
5757
}
5858

5959
# PowerShellBuild outputs to Output/<ModuleName>/<Version>/, override BHBuildOutput
60-
$projectRoot = Split-Path -Path $PSScriptRoot -Parent
60+
$projectRoot = Split-Path $PSScriptRoot -Parent
6161
$sourceManifest = Join-Path -Path $projectRoot -ChildPath "$Env:BHProjectName/$Env:BHProjectName.psd1"
62-
$moduleVersion = (Import-PowerShellDataFile -Path $sourceManifest).ModuleVersion
62+
$moduleVersion = (Import-PowerShellDataFile $sourceManifest).ModuleVersion
6363
$Env:BHBuildOutput = Join-Path -Path $projectRoot -ChildPath "Output/$Env:BHProjectName/$moduleVersion"
6464

6565
# Define the path to the module manifest
@@ -72,18 +72,18 @@ BeforeDiscovery {
7272
'Classes'
7373
) | ForEach-Object {
7474
$path = Join-Path -Path $Env:BHBuildOutput -ChildPath $_
75-
if (Test-Path -Path $path) {
76-
$global:CustomTypes += (Get-ChildItem -Path $path -Recurse -ErrorAction 'SilentlyContinue').BaseName
75+
if (Test-Path $path) {
76+
$global:CustomTypes += (Get-ChildItem $path -Recurse -ErrorAction 'SilentlyContinue').BaseName
7777
}
7878
}
7979

8080
# Remove all versions of the module from the session. Pester can't handle multiple versions.
81-
Get-Module -Name $Env:BHProjectName | Remove-Module -Force -ErrorAction 'Ignore'
82-
Import-Module -Name $moduleManifestPath -Verbose:$false -ErrorAction 'Stop'
81+
Get-Module $Env:BHProjectName | Remove-Module -Force -ErrorAction 'Ignore'
82+
Import-Module $moduleManifestPath -Verbose:$false -ErrorAction 'Stop'
8383

8484
# Get module commands
8585
$getCommandParameters = @{
86-
Module = (Get-Module -Name $Env:BHProjectName)
86+
Module = (Get-Module $Env:BHProjectName)
8787
CommandType = [System.Management.Automation.CommandTypes[]]'Cmdlet, Function' # Not alias
8888
}
8989
if ($PSVersionTable.PSVersion.Major -lt 6) {
@@ -116,10 +116,10 @@ Describe "Test help for <_.Name>" -ForEach $commands {
116116
# -ForEach, which Pester evaluates during discovery (before BeforeAll runs).
117117
$command = $_
118118
$commandName = $command.Name
119-
$commandHelp = Get-Help -Name $command.Name -ErrorAction 'SilentlyContinue'
120-
$commandParameters = global:FilterOutCommonParameters -Parameters $command.ParameterSets.Parameters
119+
$commandHelp = Get-Help $command.Name -ErrorAction 'SilentlyContinue'
120+
$commandParameters = global:FilterOutCommonParameters $command.ParameterSets.Parameters
121121
$commandParameterNames = $commandParameters.Name
122-
$helpParameters = global:FilterOutCommonParameters -Parameters $commandHelp.Parameters.Parameter
122+
$helpParameters = global:FilterOutCommonParameters $commandHelp.Parameters.Parameter
123123
$helpParameterNames = $helpParameters.Name
124124
$helpLinks = $commandHelp.relatedLinks.navigationLink.uri | Where-Object { $_ -match '^https?://' }
125125
}
@@ -128,10 +128,10 @@ Describe "Test help for <_.Name>" -ForEach $commands {
128128
# These variables are needed in both discovery and test phases so we need to duplicate them here
129129
$command = $_
130130
$commandName = $_.Name
131-
$commandHelp = Get-Help -Name $command.Name -ErrorAction 'SilentlyContinue'
132-
$commandParameters = global:FilterOutCommonParameters -Parameters $command.ParameterSets.Parameters
131+
$commandHelp = Get-Help $command.Name -ErrorAction 'SilentlyContinue'
132+
$commandParameters = global:FilterOutCommonParameters $command.ParameterSets.Parameters
133133
$commandParameterNames = $commandParameters.Name
134-
$helpParameters = global:FilterOutCommonParameters -Parameters $commandHelp.Parameters.Parameter
134+
$helpParameters = global:FilterOutCommonParameters $commandHelp.Parameters.Parameter
135135
$helpParameterNames = $helpParameters.Name
136136
}
137137

tests/Manifest.tests.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ BeforeDiscovery {
6969
}
7070

7171
# PowerShellBuild outputs to Output/<ModuleName>/<Version>/, override BHBuildOutput
72-
$projectRoot = Split-Path -Path $PSScriptRoot -Parent
72+
$projectRoot = Split-Path $PSScriptRoot -Parent
7373
$sourceManifest = Join-Path -Path $projectRoot -ChildPath "$Env:BHProjectName/$Env:BHProjectName.psd1"
74-
$moduleVersion = (Import-PowerShellDataFile -Path $sourceManifest).ModuleVersion
74+
$moduleVersion = (Import-PowerShellDataFile $sourceManifest).ModuleVersion
7575
$Env:BHBuildOutput = Join-Path -Path $projectRoot -ChildPath "Output/$Env:BHProjectName/$moduleVersion"
7676

7777
# Define the path to the module manifest
@@ -108,9 +108,9 @@ BeforeAll {
108108
}
109109

110110
# PowerShellBuild outputs to Output/<ModuleName>/<Version>/, override BHBuildOutput
111-
$projectRoot = Split-Path -Path $PSScriptRoot -Parent
111+
$projectRoot = Split-Path $PSScriptRoot -Parent
112112
$sourceManifest = Join-Path -Path $projectRoot -ChildPath "$Env:BHProjectName/$Env:BHProjectName.psd1"
113-
$moduleVersion = (Import-PowerShellDataFile -Path $sourceManifest).ModuleVersion
113+
$moduleVersion = (Import-PowerShellDataFile $sourceManifest).ModuleVersion
114114
$Env:BHBuildOutput = Join-Path -Path $projectRoot -ChildPath "Output/$Env:BHProjectName/$moduleVersion"
115115

116116
# Define the path to the module manifest
@@ -132,15 +132,15 @@ BeforeAll {
132132
$manifestRawData = Import-PowerShellDataFile @importDataFileParameters
133133

134134
# Import ManifestHelpers.psm1 for SemVer helper functions
135-
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath 'ManifestHelpers.psm1') -Verbose:$false -Force
135+
Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'ManifestHelpers.psm1') -Verbose:$false -Force
136136

137137
$requirementsPath = Join-Path -Path $env:BHProjectPath -ChildPath 'requirements.psd1'
138-
$requirements = Import-PowerShellDataFile -Path $requirementsPath -ErrorAction 'Stop'
138+
$requirements = Import-PowerShellDataFile $requirementsPath -ErrorAction 'Stop'
139139

140140
# Parse the version from the changelog
141141
$changelogPath = Join-Path -Path $Env:BHProjectPath -ChildPath 'CHANGELOG.md'
142142
$changelogVersionPattern = '^##\s\\?\[(?<Version>(\d+\.){1,3}\d+)\\?\]' # Matches on a line that starts with '## [Version]' or '## \[Version\]'
143-
$changelogVersion = Get-Content -Path $changelogPath | ForEach-Object {
143+
$changelogVersion = Get-Content $changelogPath | ForEach-Object {
144144
if ($_ -match $changelogVersionPattern) {
145145
$changelogVersion = $matches.Version
146146
break

tests/Meta.tests.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ BeforeAll {
22
Set-StrictMode -Version 'Latest'
33

44
# Make sure MetaFixers.psm1 is loaded - it contains Get-TextFilesList
5-
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath 'MetaFixers.psm1') -Verbose:$false -Force
5+
Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'MetaFixers.psm1') -Verbose:$false -Force
66

77
$projectRoot = $Env:BHProjectPath
88
if (-not $projectRoot) {
99
$projectRoot = $PSScriptRoot
1010
}
1111

12-
$allTextFiles = Get-TextFilesList -Root $projectRoot
12+
$allTextFiles = Get-TextFilesList $projectRoot
1313
$unicodeFilesCount = 0
1414
$totalTabsCount = 0
1515
foreach ($textFile in $allTextFiles) {
16-
if (Test-FileUnicode -FileInfo $textFile) {
16+
if (Test-FileUnicode $textFile) {
1717
$unicodeFilesCount++
1818
Write-Warning (
1919
"File $($textFile.FullName) contains 0x00 bytes." +
@@ -24,7 +24,7 @@ BeforeAll {
2424
$unicodeFilesCount | Should -Be 0
2525

2626
$fileName = $textFile.FullName
27-
(Get-Content -Path $fileName -Raw) | Select-String -Pattern "`t" | Foreach-Object {
27+
(Get-Content $fileName -Raw) | Select-String "`t" | Foreach-Object {
2828
Write-Warning (
2929
"There are tabs in $fileName." +
3030
' Use Fixer "Get-TextFilesList `$pwd | ConvertTo-SpaceIndentation".'

tests/MetaFixers.psm1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function ConvertTo-SpaceIndentation {
6262
)
6363

6464
process {
65-
$content = (Get-Content -Raw -Path $FileInfo.FullName) -replace "`t", ' '
65+
$content = (Get-Content -Raw $FileInfo.FullName) -replace "`t", ' '
6666
[System.IO.File]::WriteAllText($FileInfo.FullName, $content)
6767
}
6868
}
@@ -106,7 +106,7 @@ function Get-TextFilesList {
106106
}
107107

108108
process {
109-
Get-ChildItem -Path $Root -File -Recurse | Where-Object {
109+
Get-ChildItem $Root -File -Recurse | Where-Object {
110110
$_.Extension -in $textFileExtensions
111111
}
112112
}
@@ -167,6 +167,6 @@ function Get-UnicodeFilesList {
167167
)
168168

169169
$root | Get-TextFilesList | Where-Object {
170-
Test-FileUnicode -FileInfo $_
170+
Test-FileUnicode $_
171171
}
172172
}

tests/Unit/Private/Invoke-{{Prefix}}Helper.tests.ps1

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ BeforeDiscovery {
1717
}
1818

1919
# PowerShellBuild outputs to Output/<ModuleName>/<Version>/
20-
$projectRoot = Split-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -Parent
20+
$projectRoot = Split-Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) -Parent
2121
$sourceManifest = Join-Path -Path $projectRoot -ChildPath "$Env:BHProjectName/$Env:BHProjectName.psd1"
22-
$moduleVersion = (Import-PowerShellDataFile -Path $sourceManifest).ModuleVersion
22+
$moduleVersion = (Import-PowerShellDataFile $sourceManifest).ModuleVersion
2323
$Env:BHBuildOutput = Join-Path -Path $projectRoot -ChildPath "Output/$Env:BHProjectName/$moduleVersion"
2424
}
2525

2626
BeforeAll {
2727
# Import the module from the build output
2828
$moduleManifestPath = Join-Path -Path $Env:BHBuildOutput -ChildPath "$Env:BHProjectName.psd1"
29-
Get-Module -Name $Env:BHProjectName | Remove-Module -Force -ErrorAction 'Ignore'
30-
Import-Module -Name $moduleManifestPath -Force -ErrorAction 'Stop'
29+
Get-Module $Env:BHProjectName | Remove-Module -Force -ErrorAction 'Ignore'
30+
Import-Module $moduleManifestPath -Force -ErrorAction 'Stop'
3131
}
3232

3333
InModuleScope -ModuleName $Env:BHProjectName -ScriptBlock {
@@ -36,31 +36,31 @@ InModuleScope -ModuleName $Env:BHProjectName -ScriptBlock {
3636
Context 'Basic functionality' {
3737

3838
It 'Returns the processed message' {
39-
$result = Invoke-{{Prefix}}Helper -Message 'Test message'
39+
$result = Invoke-{{Prefix}}Helper 'Test message'
4040
$result | Should -Be 'Test message'
4141
}
4242

4343
It 'Trims whitespace from message' {
44-
$result = Invoke-{{Prefix}}Helper -Message ' Test message '
44+
$result = Invoke-{{Prefix}}Helper ' Test message '
4545
$result | Should -Be 'Test message'
4646
}
4747
}
4848

4949
Context 'Parameter validation' {
5050

5151
It 'Throws on empty message' {
52-
{ Invoke-{{Prefix}}Helper -Message '' } | Should -Throw
52+
{ Invoke-{{Prefix}}Helper '' } | Should -Throw
5353
}
5454

5555
It 'Throws on null message' {
56-
{ Invoke-{{Prefix}}Helper -Message $null } | Should -Throw
56+
{ Invoke-{{Prefix}}Helper $null } | Should -Throw
5757
}
5858
}
5959

6060
Context 'Verbose output' {
6161

6262
It 'Writes verbose messages when -Verbose is specified' {
63-
$verboseOutput = Invoke-{{Prefix}}Helper -Message 'Test' -Verbose 4>&1
63+
$verboseOutput = Invoke-{{Prefix}}Helper 'Test' -Verbose 4>&1
6464
$verboseOutput | Should -Not -BeNullOrEmpty
6565
}
6666
}

tests/Unit/Public/Get-{{Prefix}}Example.tests.ps1

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ BeforeDiscovery {
1717
}
1818

1919
# PowerShellBuild outputs to Output/<ModuleName>/<Version>/
20-
$projectRoot = Split-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -Parent
20+
$projectRoot = Split-Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) -Parent
2121
$sourceManifest = Join-Path -Path $projectRoot -ChildPath "$Env:BHProjectName/$Env:BHProjectName.psd1"
22-
$moduleVersion = (Import-PowerShellDataFile -Path $sourceManifest).ModuleVersion
22+
$moduleVersion = (Import-PowerShellDataFile $sourceManifest).ModuleVersion
2323
$Env:BHBuildOutput = Join-Path -Path $projectRoot -ChildPath "Output/$Env:BHProjectName/$moduleVersion"
2424
}
2525

2626
BeforeAll {
2727
# Import the module from the build output
2828
$moduleManifestPath = Join-Path -Path $Env:BHBuildOutput -ChildPath "$Env:BHProjectName.psd1"
29-
Get-Module -Name $Env:BHProjectName | Remove-Module -Force -ErrorAction 'Ignore'
30-
Import-Module -Name $moduleManifestPath -Force -ErrorAction 'Stop'
29+
Get-Module $Env:BHProjectName | Remove-Module -Force -ErrorAction 'Ignore'
30+
Import-Module $moduleManifestPath -Force -ErrorAction 'Stop'
3131
}
3232

3333
Describe 'Get-{{Prefix}}Example' {
@@ -40,7 +40,7 @@ Describe 'Get-{{Prefix}}Example' {
4040
}
4141

4242
It 'Returns a greeting with specified name' {
43-
$result = Get-{{Prefix}}Example -Name 'PowerShell'
43+
$result = Get-{{Prefix}}Example 'PowerShell'
4444
$result | Should -Be 'Hello, PowerShell!'
4545
}
4646

@@ -53,18 +53,18 @@ Describe 'Get-{{Prefix}}Example' {
5353
Context 'Parameter validation' {
5454

5555
It 'Throws on empty name' {
56-
{ Get-{{Prefix}}Example -Name '' } | Should -Throw
56+
{ Get-{{Prefix}}Example '' } | Should -Throw
5757
}
5858

5959
It 'Throws on null name' {
60-
{ Get-{{Prefix}}Example -Name $null } | Should -Throw
60+
{ Get-{{Prefix}}Example $null } | Should -Throw
6161
}
6262
}
6363

6464
Context 'Verbose output' {
6565

6666
It 'Writes verbose messages when -Verbose is specified' {
67-
$verboseOutput = Get-{{Prefix}}Example -Name 'Test' -Verbose 4>&1
67+
$verboseOutput = Get-{{Prefix}}Example 'Test' -Verbose 4>&1
6868
$verboseOutput | Should -Not -BeNullOrEmpty
6969
}
7070
}

0 commit comments

Comments
 (0)