Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions crates/oxc_linter/src/rules/eslint/no_console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ use crate::{
rule::Rule,
};

fn no_console_diagnostic(span: Span) -> OxcDiagnostic {
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("eslint(no-console): Unexpected console statement.")
.with_label(span)
.with_help("Delete this console statement.")
.with_help(only_msg)
}

#[derive(Debug, Default, Clone)]
Expand Down Expand Up @@ -90,9 +96,11 @@ impl Rule for NoConsole {
{
if let Some((mem_span, _)) = mem.static_property_info() {
let diagnostic_span = ident.span().merge(mem_span);
ctx.diagnostic_with_suggestion(no_console_diagnostic(diagnostic_span), |fixer| {
remove_console(fixer, ctx, node)
});

ctx.diagnostic_with_suggestion(
no_console_diagnostic(diagnostic_span, &self.allow),
|fixer| remove_console(fixer, ctx, node),
);
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions crates/oxc_linter/src/snapshots/eslint_no_console.snap
Original file line number Diff line number Diff line change
Expand Up @@ -55,53 +55,53 @@ source: crates/oxc_linter/src/tester.rs
1 │ console.log(foo)
· ───────────
╰────
help: Delete this console statement.
help: Supported methods are: error.

⚠ eslint(no-console): eslint(no-console): Unexpected console statement.
╭─[no_console.tsx:1:1]
1 │ console.error(foo)
· ─────────────
╰────
help: Delete this console statement.
help: Supported methods are: warn.

⚠ eslint(no-console): eslint(no-console): Unexpected console statement.
╭─[no_console.tsx:1:1]
1 │ console.info(foo)
· ────────────
╰────
help: Delete this console statement.
help: Supported methods are: log.

⚠ eslint(no-console): eslint(no-console): Unexpected console statement.
╭─[no_console.tsx:1:1]
1 │ console.warn(foo)
· ────────────
╰────
help: Delete this console statement.
help: Supported methods are: error.

⚠ eslint(no-console): eslint(no-console): Unexpected console statement.
╭─[no_console.tsx:1:1]
1 │ console.log(foo)
· ───────────
╰────
help: Delete this console statement.
help: Supported methods are: warn, info.

⚠ eslint(no-console): eslint(no-console): Unexpected console statement.
╭─[no_console.tsx:1:1]
1 │ console.error(foo)
· ─────────────
╰────
help: Delete this console statement.
help: Supported methods are: warn, info, log.

⚠ eslint(no-console): eslint(no-console): Unexpected console statement.
╭─[no_console.tsx:1:1]
1 │ console.info(foo)
· ────────────
╰────
help: Delete this console statement.
help: Supported methods are: warn, error, log.

⚠ eslint(no-console): eslint(no-console): Unexpected console statement.
╭─[no_console.tsx:1:1]
1 │ console.warn(foo)
· ────────────
╰────
help: Delete this console statement.
help: Supported methods are: info, log.
Loading