Skip to content

Commit 7a92412

Browse files
committed
Rule: AvoidShouldContinueWithoutForceParameter - Fix to consider the usage of [switch] type along with [boolean] for proper SupportsShouldContinue use
1 parent 96a0f3d commit 7a92412

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Rules/AvoidShouldContinueWithoutForce.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
4646
foreach (ParameterAst paramAst in paramAsts)
4747
{
4848
if (String.Equals(paramAst.Name.VariablePath.ToString(), "force", StringComparison.OrdinalIgnoreCase)
49-
&& String.Equals(paramAst.StaticType.FullName, "System.Boolean", StringComparison.OrdinalIgnoreCase))
49+
&& (String.Equals(paramAst.StaticType.FullName, "System.Boolean", StringComparison.OrdinalIgnoreCase)
50+
|| String.Equals(paramAst.StaticType.FullName, "System.Management.Automation.SwitchParameter", StringComparison.OrdinalIgnoreCase)))
5051
{
5152
hasForce = true;
5253
break;

Tests/Rules/GoodCmdlet.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,17 @@ function Get-Reserved*
275275
function Get-MyWidgetStatus
276276
{
277277

278+
}
279+
280+
function Get-MyFood
281+
{
282+
[CmdletBinding(SupportsShouldProcess=$true)]
283+
param([Switch]$Force)
284+
285+
process
286+
{
287+
if ($PSCmdlet.ShouldContinue("Are you sure?"))
288+
{
289+
}
290+
}
278291
}

0 commit comments

Comments
 (0)