oxc-project/oxc · warning
Unexpected console statement.
Error message
Unexpected console statement.
What it means
Diagnostic from the oxlint rule `no-console` (crates/oxc_linter/src/rules/eslint/no_console.rs). It fires on any call to a `console.*` method (log, warn, error, info, debug, trace, ...) when that method is not in the configured `allow` array. The help text adapts: with no `allow` list it says 'Delete this console statement.'; with one, it lists the supported methods, e.g. 'Supported methods are: warn, error.'.
Source
Thrown at crates/oxc_linter/src/rules/eslint/no_console.rs:25
use oxc_semantic::IsGlobalReference;
use oxc_span::{GetSpan, Span};
use oxc_str::CompactStr;
use crate::{
AstNode,
context::LintContext,
fixer::{RuleFix, RuleFixer},
rule::{DefaultRuleConfig, Rule},
};
fn no_console_diagnostic(span: Span, allow: &[CompactStr]) -> OxcDiagnostic {
let only_msg = if allow.is_empty() {
String::from("Delete this console statement.")
} else {
format!("Supported methods are: {}.", allow.join(", "))
};
OxcDiagnostic::warn("Unexpected console statement.").with_label(span).with_help(only_msg)
}
#[derive(Debug, Default, Clone, Deserialize)]
pub struct NoConsole(Box<NoConsoleConfig>);
#[derive(Debug, Default, Clone, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct NoConsoleConfig {
/// The `allow` option permits the given list of console methods to be used as exceptions to
/// this rule.
///
/// Say the option was configured as `{ "allow": ["info"] }` then the rule would behave as
/// follows:
///
/// Example of **incorrect** code for this option:
/// ```javascript
/// console.log('foo');
/// ```View on GitHub (pinned to e1e7af627c)
Solutions
- Delete the debug `console.log` statements before committing.
- Replace ad-hoc console calls with the project's logger so output is level-filtered and greppable.
- Allow intentional methods via .oxlintrc.json: `{ "rules": { "no-console": ["error", { "allow": ["warn", "error"] }] } }`.
- For scripts/tests where console use is fine, disable the rule in an `overrides` block for those globs, or suppress inline with `// oxlint-disable-next-line no-console`.
Example fix
// before
function load(config) {
console.log('loading', config);
return parse(config);
}
// after
function load(config) {
logger.debug('loading', config);
return parse(config);
} Defensive patterns
Strategy: fallback
Validate before calling
// Pre-scan changed files for console calls outside allowed set
const allowed = new Set(['warn', 'error']);
for (const m of src.matchAll(/console\.((\w+))\s*\(/g)) {
if (!allowed.has(m[1])) fail(`${file}: console.${m[1]}`);
} Prevention
- Route all output through a logger abstraction from day one.
- Encode your allow list in .oxlintrc.json (`no-console` allow) and in the pre-scan above.
- Run oxlint in CI with --deny-warnings so debug logs never merge.
When it happens
Trigger: A CallExpression whose callee is a StaticMemberExpression on the global `console` identifier with a method not in `allow` — e.g. `console.log('hi')` with default (empty) allow list. `console.warn`/`console.error` also fire unless explicitly allowed.
Common situations: Debug leftovers shipped to CI where oxlint runs with `--deny-warnings`; teams that allow `warn`/`error` but not `log` migrating their ESLint `no-console` allow list to .oxlintrc.json; test or script files accidentally covered by the same lint scope as production code.
Related errors
- Unexpected use of `{operator:?}`.
- `@yields` tag is required when using `@generator` tag.
- Use of `{method_name}` is not allowed
- The description for the @ts-{ts_comment_name} directive must
- Do not use {leading_or_trailing} spaces with `console.{metho
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/2a4061be60b835db.
Report an issue: GitHub.