C0006 print-in-library¶
Rule: Library code does not print.
| Code | C0006 (stable, never reused) |
| Id | print-in-library |
| Category | code |
| Source | spirit_level |
| Fix | by hand |
Level per tier¶
| Tier | Level | Reason |
|---|---|---|
| small | warn |
printing is the binary's choice |
| small-workspace | warn |
printing is the binary's choice |
| medium | warn |
printing is the binary's choice |
| big | warn |
printing is the binary's choice |
| ai | off | |
| embedded | off | |
| ui | off | |
| egui | off | |
| units-strict | off | |
| units-paranoid | off |
Parameters¶
| Name | Type | Default | Meaning |
|---|---|---|---|
macros |
list of strings | ["println", "eprintln", "print", "eprint", "dbg"] |
macros that print |
Why¶
Whether and where to print is the binary's decision. A library that prints writes into a GUI's terminal, a JSON stream or an agent's tool output, and cannot be silenced. dbg! left in code is debugging that escaped.
How to fix¶
Return the text, or log through log or tracing; the binary sets the output.
Clippy¶
Clippy's print_stdout and print_stderr (in the medium, big and ai tiers' Clippy set) report every print, in binaries too, unless allowed there. This lint stays on beside them: it tells a library from a binary by itself and runs without building the code.
Configure¶
[lints.print-in-library]
level = "deny"
macros = ["println", "eprintln", "print", "eprint", "dbg"]
reason = "why this project wants it at this level"
Allow one finding in the code with // spirit-level: allow(print-in-library) <reason> (waivers); the code works there too, as in [lints.C0006].