Skip to content

noConsole

Diagnostic Category: lint/suspicious/noConsole

Since: v1.6.0

Sources:

Disallow the use of console.

In a browser environment, it’s considered a best practice to log messages using console. Such messages are considered to be for debugging purposes and therefore not suitable to ship to the client. In general, calls using console should be stripped before being pushed to production.

console.error('hello world')
code-block.js:1:1 lint/suspicious/noConsole  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Don’t use console.

> 1 │ console.error(‘hello world’)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

The use of console is often reserved for debugging.

Unsafe fix: Remove console.

1 │ console.error(hello·world)
----------------------------

Use the options to explicitly allow a specific subset of console methods.

{
"options": {
"allow": ["assert", "error", "info", "warn"]
}
}
console.error("error message"); // Allowed
console.warn("warning message"); // Allowed
console.info("info message"); // Allowed
console.log("log message");
console.assert(true, "explanation"); // Allowed
code-block.js:4:1 lint/suspicious/noConsole  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Don’t use console.

2 │ console.warn(“warning message”); // Allowed
3 │ console.info(“info message”); // Allowed
> 4 │ console.log(“log message”);
^^^^^^^^^^^^^^^^^^^^^^^^^^^
5 │ console.assert(true, “explanation”); // Allowed
6 │

The use of console is often reserved for debugging.

Unsafe fix: Remove console.

2 2 console.warn(“warning message”); // Allowed
3 3 console.info(“info message”); // Allowed
4 - console.log(log·message);
5 4 console.assert(true, “explanation”); // Allowed
6 5