no-default-true-switch
What it does
Section titled “What it does”Reports a [switch] parameter with the default value $true.
Why it matters
Section titled “Why it matters”A switch is present or absent, and the caller turns it on by naming it. A switch that is on by default can be turned off only with the odd form -Name:$false.
To fix, invert the meaning, with a name for the opposite (-NoLog for -Log).
Example
Section titled “Example”... [securestring]$Secret, [string]$Name, [switch]$Force = $true, [switch]$Quiet )...Configuration
Section titled “Configuration”powershell: lint: rules: no-default-true-switch: warn # off, warn (default), errorEnabled by the presets: powershell/psscriptanalyzer.
Suppress one line with sudsy-disable-next-line no-default-true-switch 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 | PSAvoidDefaultValueSwitchParameter |
partial | Other values that evaluate to true (= 1) are not reported. |