Skip to content

Commit ce07993

Browse files
author
Kapil Borle
committed
Add documentation for UseSupportsShouldProcess rule
1 parent d4353b7 commit ce07993

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

RuleDocumentation/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
|[UsePSCredentialType](./UsePSCredentialType.md) | Warning|
4545
|[UseShouldProcessCorrectly](./UseShouldProcessCorrectly.md) | Warning|
4646
|[UseShouldProcessForStateChangingFunctions](./UseShouldProcessForStateChangingFunctions.md) | Warning|
47+
|[UseSupportsShouldProcess](./UseSupportsShouldProcess.md) | Warning|
4748
|[UseSingularNouns](./UseSingularNouns.md) | Warning|
4849
|[UseStandardDSCFunctionsInResource](./UseStandardDSCFunctionsInResource.md) | Error |
4950
|[UseToExportFieldsInManifest](./UseToExportFieldsInManifest.md) | Warning|

RuleDocumentation/UseSupportsShouldProcess.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,26 @@
22
**Severity Level: Warning**
33

44
## Description
5-
6-
## How to Fix
5+
This rule discourages manual declaration of `whatif` and `confirm` parameters in a function/cmdlet. These parameters are, however, provided automatically when a function declares a `CmdletBinding` attribute with `SupportsShouldProcess` as its named argument. Using `SupportsShouldProcess` no only provides these parameters but also some generic functionality that allows the function/cmdlet authors to provide the desired interactive experience while using the cmdlet.
76

87
## Example
9-
### Wrong:
8+
### Wrong:
109
```PowerShell
11-
10+
function foo {
11+
param(
12+
$param1,
13+
$confirm,
14+
$whatif
15+
)
16+
}
1217
```
1318

1419
### Correct:
1520
```PowerShell
16-
21+
function foo {
22+
[CmdletBinding(SupportsShouldProcess)]
23+
param(
24+
$param1
25+
)
26+
}
1727
```

0 commit comments

Comments
 (0)