Skip to content

Commit 4b7b9fd

Browse files
🩹 [Patch]: Add tests to check that functions have a param() block (#60)
## Description - Add tests to check that functions have a param() block ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent 9f240d6 commit 4b7b9fd

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

scripts/tests/PSModule/SourceCode.Tests.ps1

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,27 @@ Describe 'PSModule - SourceCode tests' {
119119
Should -BeNullOrEmpty -Because 'the script should have [CmdletBinding()] attribute'
120120
}
121121

122+
It 'Should have a param() block' {
123+
$issues = @('')
124+
$functionFiles | ForEach-Object {
125+
$found = $false
126+
$filePath = $_.FullName
127+
$relativePath = $filePath.Replace($Path, '').Trim('\').Trim('/')
128+
$scriptAst = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null)
129+
$tokens = $scriptAst.FindAll({ $args[0] -is [System.Management.Automation.Language.ParamBlockAst] }, $true)
130+
foreach ($token in $tokens) {
131+
if ($token.count -eq 1) {
132+
$found = $true
133+
}
134+
}
135+
if (-not $found) {
136+
$issues += " - $relativePath"
137+
}
138+
}
139+
$issues -join [Environment]::NewLine |
140+
Should -BeNullOrEmpty -Because 'the script should have a param() block'
141+
}
142+
122143
# It 'boolean parameters in CmdletBinding() attribute are written without assignments' {}
123144
# I.e. [CmdletBinding(ShouldProcess)] instead of [CmdletBinding(ShouldProcess = $true)]
124145
# It 'has [OutputType()] attribute' {}

0 commit comments

Comments
 (0)