Add parameter capitalization guardrail for PowerShell tests#27677
Open
Pitchfork-and-Torch wants to merge 2 commits into
Open
Add parameter capitalization guardrail for PowerShell tests#27677Pitchfork-and-Torch wants to merge 2 commits into
Pitchfork-and-Torch wants to merge 2 commits 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. |
Contributor
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. |
Comment on lines
+10
to
+11
| $repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "../../..")).Path | ||
| $scanRoot = Join-Path $repoRoot "test/powershell" |
Comment on lines
+36
to
+37
| $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:\|]|$)' |
Comment on lines
+18
to
+23
| $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.)" { |
Author
|
@microsoft-github-policy-service agree |
Author
|
/azp run |
|
Commenter does not have sufficient privileges for PR 27677 in repo PowerShell/PowerShell |
- Fix repo root path (four levels up from engine/Basic, not three) - Avoid overwriting automatic $matches variable - Allow start-of-line matches via negative lookbehind - Drop self-allowlist so the guardrail validates itself - Align It description with lowercase-only detection
Author
|
Addressed the Copilot review on the guardrail test:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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).