no-console
Disallow the use of console
has suggestions
console.log() calls added while debugging are easy to forget. In a web page they show up in every visitor's console, and in a library they write to the output of someone else's program.
Any property of the global console is reported, whether it's called or not. A local variable named console isn't.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"no-console" = "error" # or "warn"Every option, set to its default. The ones that are commented out are unset by default.
bunfig.toml
[lint.rules]
"no-console" = ["error", {
# allow = <list of strings>,
}]Examples#
example.js2 problems
console.logUnexpected console statement.("loaded", items.length);
items.forEach(console.warnUnexpected console statement.);example.jsNo problems
import { logger } from "./logger.js";
logger.info("loaded", items.length);example.jsNo problems
function report(console) {
console.log("done");
}Options#
| Option | Default | What it does |
|---|---|---|
allow | none | The console methods to allow. |
bunfig.toml
[lint.rules]
no-console = ["error", { allow = ["warn", "error"] }]example.jswith
{ "allow": ["warn", "error"] }No problemsconsole.error("could not save", reason);example.jswith
{ "allow": ["warn", "error"] }1 problemconsole.logUnexpected console statement. Only these console methods are allowed: warn, error.("saved");When not to use it#
In a CLI tool or a script, console is how the program talks to its user. Turn the rule off there.