{"record":{"id":"2a4061be60b835db","repo":"oxc-project/oxc","slug":"unexpected-console-statement","errorCode":null,"errorMessage":"Unexpected console statement.","messagePattern":"Unexpected console statement\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_console.rs","lineNumber":25,"sourceCode":"use oxc_semantic::IsGlobalReference;\nuse oxc_span::{GetSpan, Span};\nuse oxc_str::CompactStr;\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    fixer::{RuleFix, RuleFixer},\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn no_console_diagnostic(span: Span, allow: &[CompactStr]) -> OxcDiagnostic {\n    let only_msg = if allow.is_empty() {\n        String::from(\"Delete this console statement.\")\n    } else {\n        format!(\"Supported methods are: {}.\", allow.join(\", \"))\n    };\n\n    OxcDiagnostic::warn(\"Unexpected console statement.\").with_label(span).with_help(only_msg)\n}\n\n#[derive(Debug, Default, Clone, Deserialize)]\npub struct NoConsole(Box<NoConsoleConfig>);\n\n#[derive(Debug, Default, Clone, Deserialize, JsonSchema)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct NoConsoleConfig {\n    /// The `allow` option permits the given list of console methods to be used as exceptions to\n    /// this rule.\n    ///\n    /// Say the option was configured as `{ \"allow\": [\"info\"] }` then the rule would behave as\n    /// follows:\n    ///\n    /// Example of **incorrect** code for this option:\n    /// ```javascript\n    /// console.log('foo');\n    /// ```","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_console.rs#L7-L43","documentation":"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.'.","triggerScenarios":"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.","commonSituations":"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.","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`."],"exampleFix":"// before\nfunction load(config) {\n  console.log('loading', config);\n  return parse(config);\n}\n\n// after\nfunction load(config) {\n  logger.debug('loading', config);\n  return parse(config);\n}","handlingStrategy":"fallback","validationCode":"// Pre-scan changed files for console calls outside allowed set\nconst allowed = new Set(['warn', 'error']);\nfor (const m of src.matchAll(/console\\.((\\w+))\\s*\\(/g)) {\n  if (!allowed.has(m[1])) fail(`${file}: console.${m[1]}`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["lint","console","logging","config","oxlint"],"backgroundTag":"console-statement","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}