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.log("loaded", items.length);

items.forEach(console.warn);
example.jsNo problems
import { logger } from "./logger.js";

logger.info("loaded", items.length);
example.jsNo problems
function report(console) {
  console.log("done");
}

Options#

OptionDefaultWhat it does
allownoneThe console methods to allow.
bunfig.toml
[lint.rules]
no-console = ["error", { allow = ["warn", "error"] }]
example.jswith { "allow": ["warn", "error"] }No problems
console.error("could not save", reason);
example.jswith { "allow": ["warn", "error"] }1 problem
console.log("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.