Skip to content

supports-should-process

PowerShellsuspiciousno fixdefault: offpowershell/psscriptanalyzer

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.

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.

Reported
function Remove-Thing { }
function Set-Thing { [CmdletBinding(SupportsShouldProcess)] param() }
function Stop-Thing { [CmdletBinding(SupportsShouldProcess = $false)] param() }
function Get-Thing { }
function global:New-Thing { }
...
powershell:
lint:
rules:
supports-should-process: warn # off (default), warn, error

Enabled by the presets: powershell/psscriptanalyzer.

Suppress one line with sudsy-disable-next-line supports-should-process in a comment of the file’s language.

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.