Add parameter capitalization guardrail for PowerShell tests#27677
Add parameter capitalization guardrail for PowerShell tests#27677Pitchfork-and-Torch wants to merge 1 commit into
Conversation
Fixes a handful of lowercase common parameters (-force, etc.) and adds a CI test so we don't reintroduce them. Intentional case-insensitivity fixtures stay allowlisted. Addresses PowerShell#26614.
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
@Pitchfork-and-Torch please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
There was a problem hiding this comment.
Pull request overview
Adds a CI guardrail test to keep common PowerShell parameter switches in test scripts consistently capitalized (PascalCase), and fixes several existing lowercase -force call sites that triggered the issue (#26614).
Changes:
- Fixed a handful of lowercase common-parameter usages (e.g.,
-force→-Force) in existing tests. - Added a new Pester test that scans
test/powershellfor lowercase common parameters, with an allowlist for intentional fixtures. - Updated one cleanup call site in
Encoding.Tests.ps1to use-Force.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 |
Fixes a lowercase -force usage in an alias test. |
test/powershell/Modules/Microsoft.PowerShell.Management/Remove-Item.Tests.ps1 |
Fixes a lowercase -force usage when creating a test file. |
test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 |
Normalizes New-Item parameter casing (-ItemType, -Path, -Force). |
test/powershell/Modules/Microsoft.PowerShell.Core/PSSessionConfiguration.Tests.ps1 |
Fixes lowercase -force usages in pending remoting configuration tests. |
test/powershell/engine/Basic/ParameterCapitalization.Tests.ps1 |
Introduces the new CI guardrail that scans for lowercase common parameters. |
test/powershell/engine/Basic/Encoding.Tests.ps1 |
Fixes lowercase -force in test cleanup. |
| $repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "../../..")).Path | ||
| $scanRoot = Join-Path $repoRoot "test/powershell" |
| $matches = Select-String -Path $file.FullName -Pattern $parameterPattern -CaseSensitive -AllMatches | ||
| foreach ($m in $matches) { |
| # High-frequency switches that should appear PascalCase in source. | ||
| # Intentional lowercase uses (binding case-insensitivity tests, stream fixtures) | ||
| # are allowlisted by relative path below. | ||
| $parameterPattern = '(?<=[\s|])-(force|erroraction|warningaction|verbose|debug|whatif|confirm)(?=[\s:\|]|$)' |
| $allowlistRelativePaths = @( | ||
| "test/powershell/Language/Scripting/CommonParameters.Tests.ps1" | ||
| "test/powershell/Language/Parser/BNotOperator.Tests.ps1" | ||
| "test/powershell/Language/Parser/RedirectionOperator.Tests.ps1" | ||
| "test/powershell/engine/Basic/ParameterCapitalization.Tests.ps1" | ||
| ) |
| ) | ||
| } | ||
|
|
||
| It "Uses PascalCase for common parameters (no bare lowercase -force / -erroraction / etc.)" { |
Summary
Addresses #26614.
Keep test scripts using PascalCase for common parameters (
-Force,-ErrorAction, etc.).Changes
-forcecall sites (including the Set-Alias example from the issue)ParameterCapitalization.Tests.ps1(CI) scanningtest/powershellTesting
Dry-ran the scan over
test/powershellafter fixes (0 violations outside allowlist).