Skip to content

no-print

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.

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.

Reported
Write-Host "hi"
write-host
Write-Output "ok"
Get-Help Write-Host
...
Get-CimInstance Win32_Process
...
function Get-Other { Write-Host "y" }
function Get-It {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "")]
param()
...
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.

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