Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion crates/oxc_linter/src/rules/eslint/no_labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use crate::{
};

fn no_labels_diagnostic(message: &'static str, label_span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn(message).with_label(label_span)
OxcDiagnostic::warn(message)
.with_help("Consider refactoring the code to eliminate the need for labels.")
.with_label(label_span)
}

#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use oxc_span::Span;
use crate::{AstNode, context::LintContext, rule::Rule};

fn no_loss_of_precision_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("This number literal will lose precision at runtime.").with_label(span)
OxcDiagnostic::warn("This number literal will lose precision at runtime.")
.with_help("Use a number literal that can be represented accurately by a 64-bit floating-point number.")
.with_label(span)
}

#[derive(Debug, Default, Clone)]
Expand Down
4 changes: 3 additions & 1 deletion crates/oxc_linter/src/rules/eslint/no_self_assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ use crate::{
};

fn no_self_assign_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("this expression is assigned to itself").with_label(span)
OxcDiagnostic::warn("this expression is assigned to itself")
.with_help("Remove the self-assignment or assign to a different variable.")
.with_label(span)
}

#[derive(Debug, Clone, Deserialize, JsonSchema)]
Expand Down
2 changes: 2 additions & 0 deletions crates/oxc_linter/src/rules/eslint/no_useless_catch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ use crate::{AstNode, context::LintContext, rule::Rule};

fn no_useless_catch_diagnostic(catch: Span, rethrow: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Unnecessary try/catch wrapper")
.with_help("Remove the try/catch wrapper, since it does not provide any additional error handling or functionality.")
.with_labels([catch.label("is caught here"), rethrow.label("and re-thrown here")])
}

fn no_useless_catch_finalizer_diagnostic(catch: Span, rethrow: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Unnecessary catch clause")
.with_help("Remove the catch clause, since it does not provide any additional error handling or functionality beyond what the finalizer already provides.")
.with_labels([catch.label("is caught here"), rethrow.label("and re-thrown here")])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ use crate::{
};

fn prefer_promise_reject_errors_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Expected the Promise rejection reason to be an Error").with_label(span)
OxcDiagnostic::warn("Expected the Promise rejection reason to be an Error")
.with_help("Only pass an Error object to the reject() function for user-defined errors in Promises.")
.with_label(span)
}

#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]
Expand Down
39 changes: 39 additions & 0 deletions crates/oxc_linter/src/snapshots/eslint_no_labels.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,231 +7,270 @@ source: crates/oxc_linter/src/tester.rs
1 │ label: while(true) {}
· ─────
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Labeled statement is not allowed
╭─[no_labels.tsx:1:1]
1 │ label: while (true) { break label; }
· ─────
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Label in break statement is not allowed
╭─[no_labels.tsx:1:29]
1 │ label: while (true) { break label; }
· ─────
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Labeled statement is not allowed
╭─[no_labels.tsx:1:1]
1 │ label: while (true) { continue label; }
· ─────
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Label in continue statement is not allowed
╭─[no_labels.tsx:1:32]
1 │ label: while (true) { continue label; }
· ─────
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Labeled statement is not allowed
╭─[no_labels.tsx:1:1]
1 │ A: var foo = 0;
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Labeled statement is not allowed
╭─[no_labels.tsx:1:1]
1 │ A: break A;
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Label in break statement is not allowed
╭─[no_labels.tsx:1:10]
1 │ A: break A;
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Labeled statement is not allowed
╭─[no_labels.tsx:1:1]
1 │ A: { if (foo()) { break A; } bar(); };
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Label in break statement is not allowed
╭─[no_labels.tsx:1:25]
1 │ A: { if (foo()) { break A; } bar(); };
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Labeled statement is not allowed
╭─[no_labels.tsx:1:1]
1 │ A: if (a) { if (foo()) { break A; } bar(); };
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Label in break statement is not allowed
╭─[no_labels.tsx:1:32]
1 │ A: if (a) { if (foo()) { break A; } bar(); };
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Labeled statement is not allowed
╭─[no_labels.tsx:1:1]
1 │ A: switch (a) { case 0: break A; default: break; };
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Label in break statement is not allowed
╭─[no_labels.tsx:1:31]
1 │ A: switch (a) { case 0: break A; default: break; };
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Labeled statement is not allowed
╭─[no_labels.tsx:1:1]
1 │ A: switch (a) { case 0: B: { break A; } default: break; };
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Labeled statement is not allowed
╭─[no_labels.tsx:1:25]
1 │ A: switch (a) { case 0: B: { break A; } default: break; };
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Label in break statement is not allowed
╭─[no_labels.tsx:1:36]
1 │ A: switch (a) { case 0: B: { break A; } default: break; };
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Labeled statement is not allowed
╭─[no_labels.tsx:1:1]
1 │ A: var foo = 0;
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Labeled statement is not allowed
╭─[no_labels.tsx:1:1]
1 │ A: break A;
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Label in break statement is not allowed
╭─[no_labels.tsx:1:10]
1 │ A: break A;
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Labeled statement is not allowed
╭─[no_labels.tsx:1:1]
1 │ A: { if (foo()) { break A; } bar(); };
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Label in break statement is not allowed
╭─[no_labels.tsx:1:25]
1 │ A: { if (foo()) { break A; } bar(); };
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Labeled statement is not allowed
╭─[no_labels.tsx:1:1]
1 │ A: if (a) { if (foo()) { break A; } bar(); };
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Label in break statement is not allowed
╭─[no_labels.tsx:1:32]
1 │ A: if (a) { if (foo()) { break A; } bar(); };
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Labeled statement is not allowed
╭─[no_labels.tsx:1:1]
1 │ A: switch (a) { case 0: break A; default: break; };
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Label in break statement is not allowed
╭─[no_labels.tsx:1:31]
1 │ A: switch (a) { case 0: break A; default: break; };
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Labeled statement is not allowed
╭─[no_labels.tsx:1:1]
1 │ A: var foo = 0;
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Labeled statement is not allowed
╭─[no_labels.tsx:1:1]
1 │ A: break A;
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Label in break statement is not allowed
╭─[no_labels.tsx:1:10]
1 │ A: break A;
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Labeled statement is not allowed
╭─[no_labels.tsx:1:1]
1 │ A: { if (foo()) { break A; } bar(); };
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Label in break statement is not allowed
╭─[no_labels.tsx:1:25]
1 │ A: { if (foo()) { break A; } bar(); };
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Labeled statement is not allowed
╭─[no_labels.tsx:1:1]
1 │ A: if (a) { if (foo()) { break A; } bar(); };
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Label in break statement is not allowed
╭─[no_labels.tsx:1:32]
1 │ A: if (a) { if (foo()) { break A; } bar(); };
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Labeled statement is not allowed
╭─[no_labels.tsx:1:1]
1 │ A: while (a) { break A; }
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Label in break statement is not allowed
╭─[no_labels.tsx:1:22]
1 │ A: while (a) { break A; }
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Labeled statement is not allowed
╭─[no_labels.tsx:1:1]
1 │ A: do { if (b) { break A; } } while (a);
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Label in break statement is not allowed
╭─[no_labels.tsx:1:24]
1 │ A: do { if (b) { break A; } } while (a);
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Labeled statement is not allowed
╭─[no_labels.tsx:1:1]
1 │ A: for (var a in obj) { for (;;) { switch (a) { case 0: break A; } } }
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.

⚠ eslint(no-labels): Label in break statement is not allowed
╭─[no_labels.tsx:1:63]
1 │ A: for (var a in obj) { for (;;) { switch (a) { case 0: break A; } } }
· ─
╰────
help: Consider refactoring the code to eliminate the need for labels.
Loading
Loading