src/content/docs/linter/rules/no-console.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.6.0` - Diagnostic Category: [`lint/suspicious/noConsole`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule has an [**unsafe**](/linter/#unsafe-fixes) fix. - The default severity of this rule is [**warning**](/reference/diagnostics#warning). - Sources: - Same as [`no-console`](https://eslint.org/docs/latest/rules/no-console){
"linter": {
"rules": {
"suspicious": {
"noConsole": "error"
}
}
}
}
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')
Use the options to explicitly allow a specific subset of console methods.
{
"linter": {
"rules": {
"suspicious": {
"noConsole": {
"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