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
1 change: 1 addition & 0 deletions crates/oxc_linter/src/rules/eslint/no_func_assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
}

Expand Down
1 change: 1 addition & 0 deletions crates/oxc_linter/src/rules/eslint/no_label_var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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."),
Expand Down
4 changes: 3 additions & 1 deletion crates/oxc_linter/src/rules/eslint/no_multi_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
6 changes: 5 additions & 1 deletion crates/oxc_linter/src/rules/eslint/no_nested_ternary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
4 changes: 3 additions & 1 deletion crates/oxc_linter/src/rules/eslint/no_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
9 changes: 9 additions & 0 deletions crates/oxc_linter/src/snapshots/eslint_no_func_assign.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,59 +8,68 @@ 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]
1 │ function foo() { foo = bar; }
· ─┬─
· ╰── 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]
1 │ foo = bar; function foo() { };
· ─┬─
· ╰── 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]
1 │ [foo] = bar; function foo() { };
· ─┬─
· ╰── 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]
1 │ ({x: foo = 0} = bar); function foo() { };
· ─┬─
· ╰── 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]
1 │ function foo() { [foo] = bar; }
· ─┬─
· ╰── 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]
1 │ (function() { ({x: foo = 0} = bar); function foo() { }; })();
· ─┬─
· ╰── 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]
1 │ var a = function foo() { foo = 123; };
· ─┬─
· ╰── 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]
1 │ let a = function hello() { hello = 123;};
· ──┬──
· ╰── hello is re-assigned here
╰────
help: Do not re-assign a function declared as a FunctionDeclaration.
3 changes: 3 additions & 0 deletions crates/oxc_linter/src/snapshots/eslint_no_label_var.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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.
6 changes: 6 additions & 0 deletions crates/oxc_linter/src/snapshots/eslint_no_multi_str.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,40 @@ 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]
1 │ test('Line 1 \
· ─
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.
Expand Down
10 changes: 10 additions & 0 deletions crates/oxc_linter/src/snapshots/eslint_no_nested_ternary.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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.
4 changes: 4 additions & 0 deletions crates/oxc_linter/src/snapshots/eslint_no_new.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Loading