diff --git a/crates/oxc_linter/src/rules/eslint/no_func_assign.rs b/crates/oxc_linter/src/rules/eslint/no_func_assign.rs index b89ead2b869fe..7c75c670cad02 100644 --- a/crates/oxc_linter/src/rules/eslint/no_func_assign.rs +++ b/crates/oxc_linter/src/rules/eslint/no_func_assign.rs @@ -8,6 +8,7 @@ use crate::{context::LintContext, rule::Rule}; fn no_func_assign_diagnostic(name: &str, span: Span) -> OxcDiagnostic { OxcDiagnostic::warn(format!("'{name}' is a function.")) + .with_help("Do not re-assign a function declared as a FunctionDeclaration.") .with_label(span.label(format!("{name} is re-assigned here"))) } diff --git a/crates/oxc_linter/src/rules/eslint/no_label_var.rs b/crates/oxc_linter/src/rules/eslint/no_label_var.rs index 54718a39d09ce..1319f6524de9c 100644 --- a/crates/oxc_linter/src/rules/eslint/no_label_var.rs +++ b/crates/oxc_linter/src/rules/eslint/no_label_var.rs @@ -7,6 +7,7 @@ use crate::{AstNode, context::LintContext, rule::Rule}; fn no_label_var_diagnostic(name: &str, id_span: Span, label_span: Span) -> OxcDiagnostic { OxcDiagnostic::warn(format!("Found identifier '{name}' with the same name as a label.")) + .with_help("Rename either the variable or the label to avoid confusion.") .with_labels([ id_span.label(format!("Identifier '{name}' found here.")), label_span.label("Label with the same name."), diff --git a/crates/oxc_linter/src/rules/eslint/no_multi_str.rs b/crates/oxc_linter/src/rules/eslint/no_multi_str.rs index 0cebef9fce940..88a3a3537f086 100644 --- a/crates/oxc_linter/src/rules/eslint/no_multi_str.rs +++ b/crates/oxc_linter/src/rules/eslint/no_multi_str.rs @@ -6,7 +6,9 @@ use oxc_span::Span; use crate::{AstNode, context::LintContext, rule::Rule}; fn no_multi_str_diagnostic(span: Span) -> OxcDiagnostic { - OxcDiagnostic::warn("Unexpected multi string.").with_label(span) + OxcDiagnostic::warn("Unexpected multi string.") + .with_help("Multiline strings are not allowed. Use template literals or string concatenation instead.") + .with_label(span) } #[derive(Debug, Default, Clone)] diff --git a/crates/oxc_linter/src/rules/eslint/no_nested_ternary.rs b/crates/oxc_linter/src/rules/eslint/no_nested_ternary.rs index 23667f611bf27..62ad855a9c553 100644 --- a/crates/oxc_linter/src/rules/eslint/no_nested_ternary.rs +++ b/crates/oxc_linter/src/rules/eslint/no_nested_ternary.rs @@ -7,7 +7,11 @@ use oxc_span::Span; use crate::{AstNode, context::LintContext, rule::Rule}; fn no_nested_ternary_diagnostic(span: Span) -> OxcDiagnostic { - OxcDiagnostic::warn("Do not nest ternary expressions.").with_label(span) + OxcDiagnostic::warn("Do not nest ternary expressions.") + .with_help( + "Refactor nested ternary expressions into if-else statements for better readability.", + ) + .with_label(span) } #[derive(Debug, Default, Clone)] diff --git a/crates/oxc_linter/src/rules/eslint/no_new.rs b/crates/oxc_linter/src/rules/eslint/no_new.rs index 40a8e5a6d6c6a..c8b64790c1dfc 100644 --- a/crates/oxc_linter/src/rules/eslint/no_new.rs +++ b/crates/oxc_linter/src/rules/eslint/no_new.rs @@ -7,7 +7,9 @@ use oxc_span::{GetSpan, Span}; use crate::{context::LintContext, rule::Rule}; fn no_new_diagnostic(span: Span) -> OxcDiagnostic { - OxcDiagnostic::warn("Do not use 'new' for side effects.").with_label(span) + OxcDiagnostic::warn("Do not use 'new' for side effects.") + .with_help("Assign the result of 'new' to a variable or compare it to a reference.") + .with_label(span) } #[derive(Debug, Default, Clone)] diff --git a/crates/oxc_linter/src/snapshots/eslint_no_func_assign.snap b/crates/oxc_linter/src/snapshots/eslint_no_func_assign.snap index 02a844d61d469..bc87207e63c2f 100644 --- a/crates/oxc_linter/src/snapshots/eslint_no_func_assign.snap +++ b/crates/oxc_linter/src/snapshots/eslint_no_func_assign.snap @@ -8,6 +8,7 @@ source: crates/oxc_linter/src/tester.rs · ─┬─ · ╰── foo is re-assigned here ╰──── + help: Do not re-assign a function declared as a FunctionDeclaration. ⚠ eslint(no-func-assign): 'foo' is a function. ╭─[no_func_assign.tsx:1:18] @@ -15,6 +16,7 @@ source: crates/oxc_linter/src/tester.rs · ─┬─ · ╰── foo is re-assigned here ╰──── + help: Do not re-assign a function declared as a FunctionDeclaration. ⚠ eslint(no-func-assign): 'foo' is a function. ╭─[no_func_assign.tsx:1:1] @@ -22,6 +24,7 @@ source: crates/oxc_linter/src/tester.rs · ─┬─ · ╰── foo is re-assigned here ╰──── + help: Do not re-assign a function declared as a FunctionDeclaration. ⚠ eslint(no-func-assign): 'foo' is a function. ╭─[no_func_assign.tsx:1:2] @@ -29,6 +32,7 @@ source: crates/oxc_linter/src/tester.rs · ─┬─ · ╰── foo is re-assigned here ╰──── + help: Do not re-assign a function declared as a FunctionDeclaration. ⚠ eslint(no-func-assign): 'foo' is a function. ╭─[no_func_assign.tsx:1:6] @@ -36,6 +40,7 @@ source: crates/oxc_linter/src/tester.rs · ─┬─ · ╰── foo is re-assigned here ╰──── + help: Do not re-assign a function declared as a FunctionDeclaration. ⚠ eslint(no-func-assign): 'foo' is a function. ╭─[no_func_assign.tsx:1:19] @@ -43,6 +48,7 @@ source: crates/oxc_linter/src/tester.rs · ─┬─ · ╰── foo is re-assigned here ╰──── + help: Do not re-assign a function declared as a FunctionDeclaration. ⚠ eslint(no-func-assign): 'foo' is a function. ╭─[no_func_assign.tsx:1:20] @@ -50,6 +56,7 @@ source: crates/oxc_linter/src/tester.rs · ─┬─ · ╰── foo is re-assigned here ╰──── + help: Do not re-assign a function declared as a FunctionDeclaration. ⚠ eslint(no-func-assign): 'foo' is a function. ╭─[no_func_assign.tsx:1:26] @@ -57,6 +64,7 @@ source: crates/oxc_linter/src/tester.rs · ─┬─ · ╰── foo is re-assigned here ╰──── + help: Do not re-assign a function declared as a FunctionDeclaration. ⚠ eslint(no-func-assign): 'hello' is a function. ╭─[no_func_assign.tsx:1:28] @@ -64,3 +72,4 @@ source: crates/oxc_linter/src/tester.rs · ──┬── · ╰── hello is re-assigned here ╰──── + help: Do not re-assign a function declared as a FunctionDeclaration. diff --git a/crates/oxc_linter/src/snapshots/eslint_no_label_var.snap b/crates/oxc_linter/src/snapshots/eslint_no_label_var.snap index 6fca984d6e0d6..95453227f9d87 100644 --- a/crates/oxc_linter/src/snapshots/eslint_no_label_var.snap +++ b/crates/oxc_linter/src/snapshots/eslint_no_label_var.snap @@ -9,6 +9,7 @@ source: crates/oxc_linter/src/tester.rs · │ ╰── Label with the same name. · ╰── Identifier 'x' found here. ╰──── + help: Rename either the variable or the label to avoid confusion. ⚠ eslint(no-label-var): Found identifier 'x' with the same name as a label. ╭─[no_label_var.tsx:1:22] @@ -17,6 +18,7 @@ source: crates/oxc_linter/src/tester.rs · │ ╰── Label with the same name. · ╰── Identifier 'x' found here. ╰──── + help: Rename either the variable or the label to avoid confusion. ⚠ eslint(no-label-var): Found identifier 'x' with the same name as a label. ╭─[no_label_var.tsx:1:14] @@ -25,3 +27,4 @@ source: crates/oxc_linter/src/tester.rs · │ ╰── Label with the same name. · ╰── Identifier 'x' found here. ╰──── + help: Rename either the variable or the label to avoid confusion. diff --git a/crates/oxc_linter/src/snapshots/eslint_no_multi_str.snap b/crates/oxc_linter/src/snapshots/eslint_no_multi_str.snap index c0845ca5ef43c..601046f6c5f30 100644 --- a/crates/oxc_linter/src/snapshots/eslint_no_multi_str.snap +++ b/crates/oxc_linter/src/snapshots/eslint_no_multi_str.snap @@ -8,6 +8,7 @@ source: crates/oxc_linter/src/tester.rs · ─ 2 │ Line 2' ╰──── + help: Multiline strings are not allowed. Use template literals or string concatenation instead. ⚠ eslint(no-multi-str): Unexpected multi string. ╭─[no_multi_str.tsx:1:14] @@ -15,27 +16,32 @@ source: crates/oxc_linter/src/tester.rs · ─ 2 │ Line 2'); ╰──── + help: Multiline strings are not allowed. Use template literals or string concatenation instead. ⚠ eslint(no-multi-str): Unexpected multi string. ╭─[no_multi_str.tsx:1:5] 1 │ 'foo\ bar'; · ─ ╰──── + help: Multiline strings are not allowed. Use template literals or string concatenation instead. ⚠ eslint(no-multi-str): Unexpected multi string. ╭─[no_multi_str.tsx:1:5] 1 │ 'foo\
bar'; · ─ ╰──── + help: Multiline strings are not allowed. Use template literals or string concatenation instead. ⚠ eslint(no-multi-str): Unexpected multi string. ╭─[no_multi_str.tsx:1:5] 1 │ 'foo\
ar'; · ─ ╰──── + help: Multiline strings are not allowed. Use template literals or string concatenation instead. ⚠ eslint(no-multi-str): Unexpected multi string. ╭─[no_multi_str.tsx:1:2] 1 │ '\
still fails'; · ─ ╰──── + help: Multiline strings are not allowed. Use template literals or string concatenation instead. diff --git a/crates/oxc_linter/src/snapshots/eslint_no_nested_ternary.snap b/crates/oxc_linter/src/snapshots/eslint_no_nested_ternary.snap index 6a67e2541ce13..4743ce0f4eb9d 100644 --- a/crates/oxc_linter/src/snapshots/eslint_no_nested_ternary.snap +++ b/crates/oxc_linter/src/snapshots/eslint_no_nested_ternary.snap @@ -7,57 +7,67 @@ source: crates/oxc_linter/src/tester.rs 1 │ foo ? bar : baz === qux ? quxx : foobar; · ─────────────────────────────────────── ╰──── + help: Refactor nested ternary expressions into if-else statements for better readability. ⚠ eslint(no-nested-ternary): Do not nest ternary expressions. ╭─[no_nested_ternary.tsx:1:1] 1 │ foo ? baz === qux ? quxx : foobar : bar; · ─────────────────────────────────────── ╰──── + help: Refactor nested ternary expressions into if-else statements for better readability. ⚠ eslint(no-nested-ternary): Do not nest ternary expressions. ╭─[no_nested_ternary.tsx:1:14] 1 │ var result = foo ? (bar ? baz : qux) : quux; · ────────────────────────────── ╰──── + help: Refactor nested ternary expressions into if-else statements for better readability. ⚠ eslint(no-nested-ternary): Do not nest ternary expressions. ╭─[no_nested_ternary.tsx:1:14] 1 │ var result = foo ? (bar === baz ? qux : quux) : foobar; · ───────────────────────────────────────── ╰──── + help: Refactor nested ternary expressions into if-else statements for better readability. ⚠ eslint(no-nested-ternary): Do not nest ternary expressions. ╭─[no_nested_ternary.tsx:1:13] 1 │ doSomething(foo ? bar : baz ? qux : quux); · ──────────────────────────── ╰──── + help: Refactor nested ternary expressions into if-else statements for better readability. ⚠ eslint(no-nested-ternary): Do not nest ternary expressions. ╭─[no_nested_ternary.tsx:1:14] 1 │ var result = foo /* comment */ ? bar : baz ? qux : quux; · ────────────────────────────────────────── ╰──── + help: Refactor nested ternary expressions into if-else statements for better readability. ⚠ eslint(no-nested-ternary): Do not nest ternary expressions. ╭─[no_nested_ternary.tsx:1:14] 1 │ var result = foo! ? bar : baz! ? qux : quux; · ────────────────────────────── ╰──── + help: Refactor nested ternary expressions into if-else statements for better readability. ⚠ eslint(no-nested-ternary): Do not nest ternary expressions. ╭─[no_nested_ternary.tsx:1:14] 1 │ var result = foo ? bar! : (baz! ? qux : quux); · ──────────────────────────────── ╰──── + help: Refactor nested ternary expressions into if-else statements for better readability. ⚠ eslint(no-nested-ternary): Do not nest ternary expressions. ╭─[no_nested_ternary.tsx:1:14] 1 │ var result = (foo as boolean) ? bar : (baz as string) ? qux : quux; · ───────────────────────────────────────────────────── ╰──── + help: Refactor nested ternary expressions into if-else statements for better readability. ⚠ eslint(no-nested-ternary): Do not nest ternary expressions. ╭─[no_nested_ternary.tsx:1:14] 1 │ var result = foo ? (bar as string) : (baz as number ? qux : quux); · ──────────────────────────────────────────────────── ╰──── + help: Refactor nested ternary expressions into if-else statements for better readability. diff --git a/crates/oxc_linter/src/snapshots/eslint_no_new.snap b/crates/oxc_linter/src/snapshots/eslint_no_new.snap index 02cf9a9dfd489..354b598291248 100644 --- a/crates/oxc_linter/src/snapshots/eslint_no_new.snap +++ b/crates/oxc_linter/src/snapshots/eslint_no_new.snap @@ -7,21 +7,25 @@ source: crates/oxc_linter/src/tester.rs 1 │ new Date() · ──────── ╰──── + help: Assign the result of 'new' to a variable or compare it to a reference. ⚠ eslint(no-new): Do not use 'new' for side effects. ╭─[no_new.tsx:1:10] 1 │ (() => { new Date() }) · ──────── ╰──── + help: Assign the result of 'new' to a variable or compare it to a reference. ⚠ eslint(no-new): Do not use 'new' for side effects. ╭─[no_new.tsx:1:2] 1 │ (new Date()) · ──────── ╰──── + help: Assign the result of 'new' to a variable or compare it to a reference. ⚠ eslint(no-new): Do not use 'new' for side effects. ╭─[no_new.tsx:1:3] 1 │ ((new Date())) · ──────── ╰──── + help: Assign the result of 'new' to a variable or compare it to a reference.