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
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_new_native_nonconstructor_diagnostic(fn_name: &str, span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("`{fn_name}` cannot be called as a constructor.")).with_label(span)
OxcDiagnostic::warn(format!("`{fn_name}` cannot be called as a constructor."))
.with_help(format!("Remove the `new` operator to call `{fn_name}` as a function."))
.with_label(span)
}

#[derive(Debug, Default, Clone)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use crate::{
pub struct PreferExponentiationOperator;

fn prefer_exponentian_operator_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Prefer `**` over `Math.pow`.").with_label(span)
OxcDiagnostic::warn("Prefer `**` over `Math.pow`.")
.with_help("Replace `Math.pow(a, b)` with `a ** b`.")
.with_label(span)
}

declare_oxc_lint!(
Expand Down
4 changes: 3 additions & 1 deletion crates/oxc_linter/src/rules/eslint/prefer_rest_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span, ident::ARGUMENTS};

fn prefer_rest_params_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Use the rest parameters instead of `arguments`.").with_label(span)
OxcDiagnostic::warn("Use the rest parameters instead of `arguments`.")
.with_help("Replace `arguments` with rest parameters (`...args`).")
.with_label(span)
}

#[derive(Debug, Default, Clone)]
Expand Down
4 changes: 3 additions & 1 deletion crates/oxc_linter/src/rules/eslint/prefer_spread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use oxc_span::{ContentEq, Span};
use crate::{AstNode, ast_util::is_method_call, context::LintContext, rule::Rule};

fn eslint_prefer_spread_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Use spread operators instead of `.apply()`.").with_label(span)
OxcDiagnostic::warn("Use spread operators instead of `.apply()`.")
.with_help("Replace `.apply()` with spread syntax (`...args`).")
.with_label(span)
}

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

fn sort_vars_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Variable declarations should be sorted").with_label(span)
OxcDiagnostic::warn("Variable declarations should be sorted")
.with_help("Sort variable declarations in ascending order (case-sensitive by default).")
.with_label(span)
}

#[derive(Debug, Default, Clone, JsonSchema)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
---
source: crates/oxc_linter/src/tester.rs
assertion_line: 444
---

⚠ eslint(no-new-native-nonconstructor): `Symbol` cannot be called as a constructor.
╭─[no_new_native_nonconstructor.tsx:1:11]
1 │ var foo = new Symbol('foo');
· ───
╰────
help: Remove the `new` operator to call `Symbol` as a function.

⚠ eslint(no-new-native-nonconstructor): `Symbol` cannot be called as a constructor.
╭─[no_new_native_nonconstructor.tsx:1:59]
1 │ function bar() { return function Symbol() {}; } var baz = new Symbol('baz');
· ───
╰────
help: Remove the `new` operator to call `Symbol` as a function.

⚠ eslint(no-new-native-nonconstructor): `BigInt` cannot be called as a constructor.
╭─[no_new_native_nonconstructor.tsx:1:11]
1 │ var foo = new BigInt(9007199254740991);
· ───
╰────
help: Remove the `new` operator to call `BigInt` as a function.

⚠ eslint(no-new-native-nonconstructor): `BigInt` cannot be called as a constructor.
╭─[no_new_native_nonconstructor.tsx:1:59]
1 │ function bar() { return function BigInt() {}; } var baz = new BigInt(9007199254740991);
· ───
╰────
help: Remove the `new` operator to call `BigInt` as a function.
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
---
source: crates/oxc_linter/src/tester.rs
assertion_line: 444
---

⚠ eslint(prefer-exponentiation-operator): Prefer `**` over `Math.pow`.
╭─[prefer_exponentiation_operator.tsx:1:1]
1 │ globalThis.Math.pow(a, b)
· ─────────────────────────
╰────
help: Replace `globalThis.Math.pow(a, b)` with `a ** b`.
help: Replace `Math.pow(a, b)` with `a ** b`.

⚠ eslint(prefer-exponentiation-operator): Prefer `**` over `Math.pow`.
╭─[prefer_exponentiation_operator.tsx:1:1]
1 │ globalThis.Math['pow'](a, b)
· ────────────────────────────
╰────
help: Replace `globalThis.Math['pow'](a, b)` with `a ** b`.
help: Replace `Math.pow(a, b)` with `a ** b`.

⚠ eslint(prefer-exponentiation-operator): Prefer `**` over `Math.pow`.
╭─[prefer_exponentiation_operator.tsx:1:1]
Expand All @@ -29,15 +30,14 @@ source: crates/oxc_linter/src/tester.rs
1 │ ╭─▶ Math.pow(a, b) + Math.pow(c,
2 │ ╰─▶ d)
╰────
help: Replace `Math.pow(c,
d)` with `c ** d`.
help: Replace `Math.pow(a, b)` with `a ** b`.

⚠ eslint(prefer-exponentiation-operator): Prefer `**` over `Math.pow`.
╭─[prefer_exponentiation_operator.tsx:1:1]
1 │ Math.pow(Math.pow(a, b), Math.pow(c, d))
· ────────────────────────────────────────
╰────
help: Replace `Math.pow(Math.pow(a, b), Math.pow(c, d))` with `Math.pow(a, b) ** Math.pow(c, d)`.
help: Replace `Math.pow(a, b)` with `a ** b`.

⚠ eslint(prefer-exponentiation-operator): Prefer `**` over `Math.pow`.
╭─[prefer_exponentiation_operator.tsx:1:10]
Expand All @@ -51,42 +51,42 @@ source: crates/oxc_linter/src/tester.rs
1 │ Math.pow(Math.pow(a, b), Math.pow(c, d))
· ──────────────
╰────
help: Replace `Math.pow(c, d)` with `c ** d`.
help: Replace `Math.pow(a, b)` with `a ** b`.

⚠ eslint(prefer-exponentiation-operator): Prefer `**` over `Math.pow`.
╭─[prefer_exponentiation_operator.tsx:1:1]
1 │ Math.pow(a, b)**Math.pow(c, d)
· ──────────────
╰────
help: Replace `Math.pow(a, b)` with `(a ** b)`.
help: Replace `Math.pow(a, b)` with `a ** b`.

⚠ eslint(prefer-exponentiation-operator): Prefer `**` over `Math.pow`.
╭─[prefer_exponentiation_operator.tsx:1:17]
1 │ Math.pow(a, b)**Math.pow(c, d)
· ──────────────
╰────
help: Replace `Math.pow(c, d)` with `c ** d`.
help: Replace `Math.pow(a, b)` with `a ** b`.

⚠ eslint(prefer-exponentiation-operator): Prefer `**` over `Math.pow`.
╭─[prefer_exponentiation_operator.tsx:1:1]
1 │ Math.pow(a, b as any)
· ─────────────────────
╰────
help: Replace `Math.pow(a, b as any)` with `a ** (b as any)`.
help: Replace `Math.pow(a, b)` with `a ** b`.

⚠ eslint(prefer-exponentiation-operator): Prefer `**` over `Math.pow`.
╭─[prefer_exponentiation_operator.tsx:1:1]
1 │ Math.pow(a as any, b)
· ─────────────────────
╰────
help: Replace `Math.pow(a as any, b)` with `(a as any) ** b`.
help: Replace `Math.pow(a, b)` with `a ** b`.

⚠ eslint(prefer-exponentiation-operator): Prefer `**` over `Math.pow`.
╭─[prefer_exponentiation_operator.tsx:1:1]
1 │ Math.pow(a, b) as any
· ──────────────
╰────
help: Replace `Math.pow(a, b)` with `(a ** b)`.
help: Replace `Math.pow(a, b)` with `a ** b`.

⚠ eslint(prefer-exponentiation-operator): Prefer `**` over `Math.pow`.
╭─[prefer_exponentiation_operator.tsx:1:1]
Expand All @@ -100,3 +100,4 @@ source: crates/oxc_linter/src/tester.rs
1 │ Math.pow(a, b) + Math.pow(c, /* comment */ d)
· ────────────────────────────
╰────
help: Replace `Math.pow(a, b)` with `a ** b`.
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
---
source: crates/oxc_linter/src/tester.rs
assertion_line: 444
---

⚠ eslint(prefer-rest-params): Use the rest parameters instead of `arguments`.
╭─[prefer_rest_params.tsx:1:18]
1 │ function foo() { arguments; }
· ─────────
╰────
help: Replace `arguments` with rest parameters (`...args`).

⚠ eslint(prefer-rest-params): Use the rest parameters instead of `arguments`.
╭─[prefer_rest_params.tsx:1:18]
1 │ function foo() { arguments[0]; }
· ─────────
╰────
help: Replace `arguments` with rest parameters (`...args`).

⚠ eslint(prefer-rest-params): Use the rest parameters instead of `arguments`.
╭─[prefer_rest_params.tsx:1:18]
1 │ function foo() { arguments[1]; }
· ─────────
╰────
help: Replace `arguments` with rest parameters (`...args`).

⚠ eslint(prefer-rest-params): Use the rest parameters instead of `arguments`.
╭─[prefer_rest_params.tsx:1:18]
1 │ function foo() { arguments[Symbol.iterator]; }
· ─────────
╰────
help: Replace `arguments` with rest parameters (`...args`).
19 changes: 19 additions & 0 deletions crates/oxc_linter/src/snapshots/eslint_prefer_spread.snap
Original file line number Diff line number Diff line change
@@ -1,112 +1,131 @@
---
source: crates/oxc_linter/src/tester.rs
assertion_line: 444
---

⚠ eslint(prefer-spread): Use spread operators instead of `.apply()`.
╭─[prefer_spread.tsx:1:1]
1 │ foo.apply(undefined, args);
· ──────────────────────────
╰────
help: Replace `.apply()` with spread syntax (`...args`).

⚠ eslint(prefer-spread): Use spread operators instead of `.apply()`.
╭─[prefer_spread.tsx:1:1]
1 │ foo.apply(void 0, args);
· ───────────────────────
╰────
help: Replace `.apply()` with spread syntax (`...args`).

⚠ eslint(prefer-spread): Use spread operators instead of `.apply()`.
╭─[prefer_spread.tsx:1:1]
1 │ foo.apply(null, args);
· ─────────────────────
╰────
help: Replace `.apply()` with spread syntax (`...args`).

⚠ eslint(prefer-spread): Use spread operators instead of `.apply()`.
╭─[prefer_spread.tsx:1:1]
1 │ obj.foo.apply(obj, args);
· ────────────────────────
╰────
help: Replace `.apply()` with spread syntax (`...args`).

⚠ eslint(prefer-spread): Use spread operators instead of `.apply()`.
╭─[prefer_spread.tsx:1:1]
1 │ a.b.c.foo.apply(a.b.c, args);
· ────────────────────────────
╰────
help: Replace `.apply()` with spread syntax (`...args`).

⚠ eslint(prefer-spread): Use spread operators instead of `.apply()`.
╭─[prefer_spread.tsx:1:1]
1 │ a.b(x, y).c.foo.apply(a.b(x, y).c, args);
· ────────────────────────────────────────
╰────
help: Replace `.apply()` with spread syntax (`...args`).

⚠ eslint(prefer-spread): Use spread operators instead of `.apply()`.
╭─[prefer_spread.tsx:1:1]
1 │ [].concat.apply([ ], args);
· ──────────────────────────
╰────
help: Replace `.apply()` with spread syntax (`...args`).

⚠ eslint(prefer-spread): Use spread operators instead of `.apply()`.
╭─[prefer_spread.tsx:1:1]
1 │ ╭─▶ [].concat.apply([
2 │ │ /*empty*/
3 │ ╰─▶ ], args);
╰────
help: Replace `.apply()` with spread syntax (`...args`).

⚠ eslint(prefer-spread): Use spread operators instead of `.apply()`.
╭─[prefer_spread.tsx:1:1]
1 │ foo.apply?.(undefined, args);
· ────────────────────────────
╰────
help: Replace `.apply()` with spread syntax (`...args`).

⚠ eslint(prefer-spread): Use spread operators instead of `.apply()`.
╭─[prefer_spread.tsx:1:1]
1 │ foo?.apply(undefined, args);
· ───────────────────────────
╰────
help: Replace `.apply()` with spread syntax (`...args`).

⚠ eslint(prefer-spread): Use spread operators instead of `.apply()`.
╭─[prefer_spread.tsx:1:1]
1 │ foo?.apply?.(undefined, args);
· ─────────────────────────────
╰────
help: Replace `.apply()` with spread syntax (`...args`).

⚠ eslint(prefer-spread): Use spread operators instead of `.apply()`.
╭─[prefer_spread.tsx:1:1]
1 │ (foo?.apply)(undefined, args);
· ─────────────────────────────
╰────
help: Replace `.apply()` with spread syntax (`...args`).

⚠ eslint(prefer-spread): Use spread operators instead of `.apply()`.
╭─[prefer_spread.tsx:1:1]
1 │ (foo?.apply)?.(undefined, args);
· ───────────────────────────────
╰────
help: Replace `.apply()` with spread syntax (`...args`).

⚠ eslint(prefer-spread): Use spread operators instead of `.apply()`.
╭─[prefer_spread.tsx:1:1]
1 │ (obj?.foo).apply(obj, args);
· ───────────────────────────
╰────
help: Replace `.apply()` with spread syntax (`...args`).

⚠ eslint(prefer-spread): Use spread operators instead of `.apply()`.
╭─[prefer_spread.tsx:1:1]
1 │ a?.b.c.foo.apply(a?.b.c, args);
· ──────────────────────────────
╰────
help: Replace `.apply()` with spread syntax (`...args`).

⚠ eslint(prefer-spread): Use spread operators instead of `.apply()`.
╭─[prefer_spread.tsx:1:1]
1 │ (a?.b.c).foo.apply(a?.b.c, args);
· ────────────────────────────────
╰────
help: Replace `.apply()` with spread syntax (`...args`).

⚠ eslint(prefer-spread): Use spread operators instead of `.apply()`.
╭─[prefer_spread.tsx:1:1]
1 │ (a?.b).c.foo.apply((a?.b).c, args);
· ──────────────────────────────────
╰────
help: Replace `.apply()` with spread syntax (`...args`).

⚠ eslint(prefer-spread): Use spread operators instead of `.apply()`.
╭─[prefer_spread.tsx:1:25]
1 │ class C { #foo; foo() { obj.#foo.apply(obj, args); } }
· ─────────────────────────
╰────
help: Replace `.apply()` with spread syntax (`...args`).
Loading
Loading