supports-should-process
What it does
Section titled “What it does”Reports a function whose name has the verb New, Set, Remove, Start, Stop, Restart, Reset or Update and whose text has no SupportsShouldProcess, or has SupportsShouldProcess = $false.
Why it matters
Section titled “Why it matters”A command that changes something is expected to accept -WhatIf and -Confirm, so a user can see what it would do first. Without SupportsShouldProcess, they are not available and the user must run it to find out.
To fix, add [CmdletBinding(SupportsShouldProcess)] and call $PSCmdlet.ShouldProcess(...) before the change.
Example
Section titled “Example”function Remove-Thing { }function Set-Thing { [CmdletBinding(SupportsShouldProcess)] param() }function Stop-Thing { [CmdletBinding(SupportsShouldProcess = $false)] param() }function Get-Thing { }function global:New-Thing { }...Configuration
Section titled “Configuration”powershell: lint: rules: supports-should-process: warn # off (default), warn, errorEnabled by the presets: powershell/psscriptanalyzer.
Suppress one line with sudsy-disable-next-line supports-should-process in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.
| Tool | Rule | Match | What differs |
|---|---|---|---|
| psscriptanalyzer | PSUseShouldProcessForStateChangingFunctions |
partial | The verbs are the module’s (New, Set, Remove, Start, Stop, Restart, Reset, Update); the attribute is looked for in the whole text of the function, nested functions included. |