no-print
What it does
Section titled “What it does”Reports a call of one of the calls that write to the console, unless an argument matching redirect sends the output elsewhere and none matching console sends it back to the console. Each language lists its calls and the two patterns in its grammar’s rule row.
Why it matters
Section titled “Why it matters”A print call is usually debugging that was left in. It cannot be turned off by configuration, has no level or timestamp and ends up on the wrong stream in a service, where a logger is configured and read.
To fix, use the project’s logger, or delete the call.
Example
Section titled “Example”Write-Host "hi"write-hostWrite-Output "ok"Get-Help Write-Host...Get-CimInstance Win32_Process...function Get-Other { Write-Host "y" }function Get-It { [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "")] param()...Configuration
Section titled “Configuration”powershell: lint: rules: no-print: level: warn # off (default), warn, error options: calls: ["Write-Host"] redirect: "\\b\\B" console: "\\b\\B"python: lint: rules: no-print: level: warn # off (default), warn, error options: calls: ["Write-Host"] redirect: "\\b\\B" console: "\\b\\B"| Option | Type | Default | Description |
|---|---|---|---|
calls |
list | ["Write-Host"] |
Calls that print |
redirect |
string | "\\b\\B" |
An argument that sends the output elsewhere |
console |
string | "\\b\\B" |
An argument that sends the output to the console |
Enabled by the presets: powershell/psscriptanalyzer.
Suppress one line with sudsy-disable-next-line no-print in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| psscriptanalyzer | PSAvoidUsingWriteHost |
full |
| ruff | T201 |
full |
| ruff | T203 |
full |