You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
+6-3Lines changed: 6 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -78,10 +78,11 @@ applyTo: "**/*.ps?(m|d)1"
78
78
- Include a `Force` parameter for functions that uses `$PSCmdlet.ShouldContinue` or `$PSCmdlet.ShouldProcess`
79
79
- For state-changing functions, use `SupportsShouldProcess`
80
80
- Place ShouldProcess check immediately before each state-change
81
+
- Set `ConfirmImpact` to 'Low', 'Medium', or 'High' depending on risk
81
82
-`$PSCmdlet.ShouldProcess` must use required pattern
82
83
- Inside `$PSCmdlet.ShouldProcess`-block, avoid using `Write-Verbose`
83
84
- Never use backtick as line continuation in production code.
84
-
- Set `$ErrorActionPreference = 'Stop'` before commands using `-ErrorAction 'Stop'`; restore after
85
+
- Set `$ErrorActionPreference = 'Stop'` before commands using `-ErrorAction 'Stop'`; restore previous value after
85
86
86
87
## Output streams
87
88
@@ -90,8 +91,8 @@ applyTo: "**/*.ps?(m|d)1"
90
91
- Use `Write-Verbose` for: High-level execution flow only; User-actionable information
91
92
- Use `Write-Information` for: User-facing status updates; Important operational messages; Non-error state changes
92
93
- Use `Write-Warning` for: Non-fatal issues requiring attention; Deprecated functionality usage; Configuration problems that don't block execution
93
-
- Use `$PSCmdlet.ThrowTerminatingError()` for terminating errors (except for classes), use relevant error category, in try-catch include exception
94
-
- Use `Write-Error` for non-terminating errors, use relevant error category
94
+
- Use `$PSCmdlet.ThrowTerminatingError()` for terminating errors (except for classes), use relevant error category, in try-catch include exception with localized message
95
+
- Use `Write-Error` for non-terminating errors, use relevant error category; always use `return` after `Write-Error` to avoid further processing
95
96
96
97
## ShouldProcess Required Pattern
97
98
@@ -184,6 +185,7 @@ function Get-Something
184
185
- Assign function results to variables rather than inline calls
185
186
- Return a single, consistent object type per function
186
187
- return `$null` for no objects/non-terminating errors
188
+
- Use `::new()` static method instead of `New-Object` for .NET types, e.g `[System.Management.Automation.ErrorRecord]::new()`
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Suppressing this rule because Script Analyzer does not understand Pester syntax.')]
0 commit comments