diff --git a/crates/oxc_linter/src/rules/eslint/no_restricted_globals.rs b/crates/oxc_linter/src/rules/eslint/no_restricted_globals.rs index 5131f08a7eafd..86eb33f3e936e 100644 --- a/crates/oxc_linter/src/rules/eslint/no_restricted_globals.rs +++ b/crates/oxc_linter/src/rules/eslint/no_restricted_globals.rs @@ -15,7 +15,9 @@ fn no_restricted_globals(global_name: &str, suffix: &str, span: Span) -> OxcDiag format!("Unexpected use of '{global_name}'. {suffix}") }; - OxcDiagnostic::warn(warn_text).with_label(span) + OxcDiagnostic::warn(warn_text) + .with_help("Use a local variable or function parameter instead of the restricted global.") + .with_label(span) } #[derive(Debug, Default, Clone, JsonSchema)] diff --git a/crates/oxc_linter/src/rules/eslint/no_unused_private_class_members.rs b/crates/oxc_linter/src/rules/eslint/no_unused_private_class_members.rs index a47b0637a2481..5280db6b79a13 100644 --- a/crates/oxc_linter/src/rules/eslint/no_unused_private_class_members.rs +++ b/crates/oxc_linter/src/rules/eslint/no_unused_private_class_members.rs @@ -9,7 +9,9 @@ use oxc_syntax::class::ElementKind; use crate::{context::LintContext, rule::Rule}; fn no_unused_private_class_members_diagnostic(name: &str, span: Span) -> OxcDiagnostic { - OxcDiagnostic::warn(format!("'{name}' is defined but never used.")).with_label(span) + OxcDiagnostic::warn(format!("'{name}' is defined but never used.")) + .with_help("Remove the declaration or use it in the code.") + .with_label(span) } #[derive(Debug, Default, Clone)] diff --git a/crates/oxc_linter/src/snapshots/eslint_no_restricted_globals.snap b/crates/oxc_linter/src/snapshots/eslint_no_restricted_globals.snap index 47d0e94ba0a67..e3d0b1b36bd04 100644 --- a/crates/oxc_linter/src/snapshots/eslint_no_restricted_globals.snap +++ b/crates/oxc_linter/src/snapshots/eslint_no_restricted_globals.snap @@ -7,129 +7,151 @@ source: crates/oxc_linter/src/tester.rs 1 │ foo · ─── ╰──── + help: Use a local variable or function parameter instead of the restricted global. ⚠ eslint(no-restricted-globals): Unexpected use of 'foo'. ╭─[no_restricted_globals.tsx:1:17] 1 │ function fn() { foo; } · ─── ╰──── + help: Use a local variable or function parameter instead of the restricted global. ⚠ eslint(no-restricted-globals): Unexpected use of 'foo'. ╭─[no_restricted_globals.tsx:1:17] 1 │ function fn() { foo; } · ─── ╰──── + help: Use a local variable or function parameter instead of the restricted global. ⚠ eslint(no-restricted-globals): Unexpected use of 'event'. ╭─[no_restricted_globals.tsx:1:1] 1 │ event · ───── ╰──── + help: Use a local variable or function parameter instead of the restricted global. ⚠ eslint(no-restricted-globals): Unexpected use of 'foo'. ╭─[no_restricted_globals.tsx:1:1] 1 │ foo · ─── ╰──── + help: Use a local variable or function parameter instead of the restricted global. ⚠ eslint(no-restricted-globals): Unexpected use of 'foo'. ╭─[no_restricted_globals.tsx:1:1] 1 │ foo() · ─── ╰──── + help: Use a local variable or function parameter instead of the restricted global. ⚠ eslint(no-restricted-globals): Unexpected use of 'foo'. ╭─[no_restricted_globals.tsx:1:1] 1 │ foo.bar() · ─── ╰──── + help: Use a local variable or function parameter instead of the restricted global. ⚠ eslint(no-restricted-globals): Unexpected use of 'foo'. ╭─[no_restricted_globals.tsx:1:1] 1 │ foo · ─── ╰──── + help: Use a local variable or function parameter instead of the restricted global. ⚠ eslint(no-restricted-globals): Unexpected use of 'foo'. ╭─[no_restricted_globals.tsx:1:17] 1 │ function fn() { foo; } · ─── ╰──── + help: Use a local variable or function parameter instead of the restricted global. ⚠ eslint(no-restricted-globals): Unexpected use of 'foo'. ╭─[no_restricted_globals.tsx:1:17] 1 │ function fn() { foo; } · ─── ╰──── + help: Use a local variable or function parameter instead of the restricted global. ⚠ eslint(no-restricted-globals): Unexpected use of 'event'. ╭─[no_restricted_globals.tsx:1:1] 1 │ event · ───── ╰──── + help: Use a local variable or function parameter instead of the restricted global. ⚠ eslint(no-restricted-globals): Unexpected use of 'foo'. ╭─[no_restricted_globals.tsx:1:1] 1 │ foo · ─── ╰──── + help: Use a local variable or function parameter instead of the restricted global. ⚠ eslint(no-restricted-globals): Unexpected use of 'foo'. ╭─[no_restricted_globals.tsx:1:1] 1 │ foo() · ─── ╰──── + help: Use a local variable or function parameter instead of the restricted global. ⚠ eslint(no-restricted-globals): Unexpected use of 'foo'. ╭─[no_restricted_globals.tsx:1:1] 1 │ foo.bar() · ─── ╰──── + help: Use a local variable or function parameter instead of the restricted global. ⚠ eslint(no-restricted-globals): Unexpected use of 'foo'. Use bar instead. ╭─[no_restricted_globals.tsx:1:1] 1 │ foo · ─── ╰──── + help: Use a local variable or function parameter instead of the restricted global. ⚠ eslint(no-restricted-globals): Unexpected use of 'foo'. Use bar instead. ╭─[no_restricted_globals.tsx:1:17] 1 │ function fn() { foo; } · ─── ╰──── + help: Use a local variable or function parameter instead of the restricted global. ⚠ eslint(no-restricted-globals): Unexpected use of 'foo'. Use bar instead. ╭─[no_restricted_globals.tsx:1:17] 1 │ function fn() { foo; } · ─── ╰──── + help: Use a local variable or function parameter instead of the restricted global. ⚠ eslint(no-restricted-globals): Unexpected use of 'event'. Use local event parameter. ╭─[no_restricted_globals.tsx:1:1] 1 │ event · ───── ╰──── + help: Use a local variable or function parameter instead of the restricted global. ⚠ eslint(no-restricted-globals): Unexpected use of 'foo'. Use bar instead. ╭─[no_restricted_globals.tsx:1:1] 1 │ foo · ─── ╰──── + help: Use a local variable or function parameter instead of the restricted global. ⚠ eslint(no-restricted-globals): Unexpected use of 'foo'. Use bar instead. ╭─[no_restricted_globals.tsx:1:1] 1 │ foo() · ─── ╰──── + help: Use a local variable or function parameter instead of the restricted global. ⚠ eslint(no-restricted-globals): Unexpected use of 'foo'. Use bar instead. ╭─[no_restricted_globals.tsx:1:1] 1 │ foo.bar() · ─── ╰──── + help: Use a local variable or function parameter instead of the restricted global. ⚠ eslint(no-restricted-globals): Unexpected use of 'hasOwnProperty'. ╭─[no_restricted_globals.tsx:1:18] 1 │ var foo = obj => hasOwnProperty(obj, 'name'); · ────────────── ╰──── + help: Use a local variable or function parameter instead of the restricted global. diff --git a/crates/oxc_linter/src/snapshots/eslint_no_unused_private_class_members.snap b/crates/oxc_linter/src/snapshots/eslint_no_unused_private_class_members.snap index 77cb2c1ed188e..6b111c74b11b2 100644 --- a/crates/oxc_linter/src/snapshots/eslint_no_unused_private_class_members.snap +++ b/crates/oxc_linter/src/snapshots/eslint_no_unused_private_class_members.snap @@ -9,6 +9,7 @@ source: crates/oxc_linter/src/tester.rs · ───────────── 3 │ } ╰──── + help: Remove the declaration or use it in the code. ⚠ eslint(no-unused-private-class-members): 'unusedMemberInSecondClass' is defined but never used. ╭─[no_unused_private_class_members.tsx:3:17] @@ -17,6 +18,7 @@ source: crates/oxc_linter/src/tester.rs · ────────────────────────── 4 │ } ╰──── + help: Remove the declaration or use it in the code. ⚠ eslint(no-unused-private-class-members): 'unusedMemberInFirstClass' is defined but never used. ╭─[no_unused_private_class_members.tsx:2:17] @@ -25,6 +27,7 @@ source: crates/oxc_linter/src/tester.rs · ───────────────────────── 3 │ } ╰──── + help: Remove the declaration or use it in the code. ⚠ eslint(no-unused-private-class-members): 'firstUnusedMemberInSameClass' is defined but never used. ╭─[no_unused_private_class_members.tsx:2:17] @@ -33,6 +36,7 @@ source: crates/oxc_linter/src/tester.rs · ───────────────────────────── 3 │ #secondUnusedMemberInSameClass = 5; ╰──── + help: Remove the declaration or use it in the code. ⚠ eslint(no-unused-private-class-members): 'secondUnusedMemberInSameClass' is defined but never used. ╭─[no_unused_private_class_members.tsx:3:17] @@ -41,6 +45,7 @@ source: crates/oxc_linter/src/tester.rs · ────────────────────────────── 4 │ } ╰──── + help: Remove the declaration or use it in the code. ⚠ eslint(no-unused-private-class-members): 'usedOnlyInWrite' is defined but never used. ╭─[no_unused_private_class_members.tsx:2:17] @@ -49,6 +54,7 @@ source: crates/oxc_linter/src/tester.rs · ──────────────── 3 │ method() { ╰──── + help: Remove the declaration or use it in the code. ⚠ eslint(no-unused-private-class-members): 'usedOnlyInWriteStatement' is defined but never used. ╭─[no_unused_private_class_members.tsx:2:17] @@ -57,6 +63,7 @@ source: crates/oxc_linter/src/tester.rs · ───────────────────────── 3 │ method() { ╰──── + help: Remove the declaration or use it in the code. ⚠ eslint(no-unused-private-class-members): 'usedOnlyInIncrement' is defined but never used. ╭─[no_unused_private_class_members.tsx:2:17] @@ -65,6 +72,7 @@ source: crates/oxc_linter/src/tester.rs · ──────────────────── 3 │ ╰──── + help: Remove the declaration or use it in the code. ⚠ eslint(no-unused-private-class-members): 'unusedInOuterClass' is defined but never used. ╭─[no_unused_private_class_members.tsx:2:17] @@ -73,6 +81,7 @@ source: crates/oxc_linter/src/tester.rs · ─────────────────── 3 │ ╰──── + help: Remove the declaration or use it in the code. ⚠ eslint(no-unused-private-class-members): 'unusedOnlyInSecondNestedClass' is defined but never used. ╭─[no_unused_private_class_members.tsx:20:25] @@ -81,6 +90,7 @@ source: crates/oxc_linter/src/tester.rs · ────────────────────────────── 21 │ } ╰──── + help: Remove the declaration or use it in the code. ⚠ eslint(no-unused-private-class-members): 'unusedMethod' is defined but never used. ╭─[no_unused_private_class_members.tsx:2:17] @@ -89,6 +99,7 @@ source: crates/oxc_linter/src/tester.rs · ───────────── 3 │ } ╰──── + help: Remove the declaration or use it in the code. ⚠ eslint(no-unused-private-class-members): 'unusedMethod' is defined but never used. ╭─[no_unused_private_class_members.tsx:2:17] @@ -97,6 +108,7 @@ source: crates/oxc_linter/src/tester.rs · ───────────── 3 │ #usedMethod() { ╰──── + help: Remove the declaration or use it in the code. ⚠ eslint(no-unused-private-class-members): 'unusedSetter' is defined but never used. ╭─[no_unused_private_class_members.tsx:2:21] @@ -105,6 +117,7 @@ source: crates/oxc_linter/src/tester.rs · ───────────── 3 │ } ╰──── + help: Remove the declaration or use it in the code. ⚠ eslint(no-unused-private-class-members): 'unusedForInLoop' is defined but never used. ╭─[no_unused_private_class_members.tsx:2:17] @@ -113,6 +126,7 @@ source: crates/oxc_linter/src/tester.rs · ──────────────── 3 │ method() { ╰──── + help: Remove the declaration or use it in the code. ⚠ eslint(no-unused-private-class-members): 'unusedForOfLoop' is defined but never used. ╭─[no_unused_private_class_members.tsx:2:17] @@ -121,6 +135,7 @@ source: crates/oxc_linter/src/tester.rs · ──────────────── 3 │ method() { ╰──── + help: Remove the declaration or use it in the code. ⚠ eslint(no-unused-private-class-members): 'unusedInDestructuring' is defined but never used. ╭─[no_unused_private_class_members.tsx:2:17] @@ -129,6 +144,7 @@ source: crates/oxc_linter/src/tester.rs · ────────────────────── 3 │ method() { ╰──── + help: Remove the declaration or use it in the code. ⚠ eslint(no-unused-private-class-members): 'unusedInRestPattern' is defined but never used. ╭─[no_unused_private_class_members.tsx:2:17] @@ -137,6 +153,7 @@ source: crates/oxc_linter/src/tester.rs · ──────────────────── 3 │ method() { ╰──── + help: Remove the declaration or use it in the code. ⚠ eslint(no-unused-private-class-members): 'unusedInAssignmentPattern' is defined but never used. ╭─[no_unused_private_class_members.tsx:2:17] @@ -145,6 +162,7 @@ source: crates/oxc_linter/src/tester.rs · ────────────────────────── 3 │ method() { ╰──── + help: Remove the declaration or use it in the code. ⚠ eslint(no-unused-private-class-members): 'unusedInAssignmentPattern' is defined but never used. ╭─[no_unused_private_class_members.tsx:2:17] @@ -153,6 +171,7 @@ source: crates/oxc_linter/src/tester.rs · ────────────────────────── 3 │ method() { ╰──── + help: Remove the declaration or use it in the code. ⚠ eslint(no-unused-private-class-members): 'usedOnlyInTheSecondInnerClass' is defined but never used. ╭─[no_unused_private_class_members.tsx:2:17] @@ -161,45 +180,53 @@ source: crates/oxc_linter/src/tester.rs · ────────────────────────────── 3 │ ╰──── + help: Remove the declaration or use it in the code. ⚠ eslint(no-unused-private-class-members): 'awaitedMember' is defined but never used. ╭─[no_unused_private_class_members.tsx:1:13] 1 │ class Foo { #awaitedMember; async method() { await this.#awaitedMember; } } · ────────────── ╰──── + help: Remove the declaration or use it in the code. ⚠ eslint(no-unused-private-class-members): 'unused' is defined but never used. ╭─[no_unused_private_class_members.tsx:1:13] 1 │ class Foo { #unused; method() { Math.random() > 0.5 ? this.#unused : []; } } · ─────── ╰──── + help: Remove the declaration or use it in the code. ⚠ eslint(no-unused-private-class-members): 'x' is defined but never used. ╭─[no_unused_private_class_members.tsx:1:13] 1 │ class Foo { #x; #y; method(a, b, c) { a ? (b ? this.#x : c) : this.#y; } } · ── ╰──── + help: Remove the declaration or use it in the code. ⚠ eslint(no-unused-private-class-members): 'y' is defined but never used. ╭─[no_unused_private_class_members.tsx:1:17] 1 │ class Foo { #x; #y; method(a, b, c) { a ? (b ? this.#x : c) : this.#y; } } · ── ╰──── + help: Remove the declaration or use it in the code. ⚠ eslint(no-unused-private-class-members): 'x' is defined but never used. ╭─[no_unused_private_class_members.tsx:1:13] 1 │ class Foo { #x; method() { a && (b ? this.#x : c); } } · ── ╰──── + help: Remove the declaration or use it in the code. ⚠ eslint(no-unused-private-class-members): 'b' is defined but never used. ╭─[no_unused_private_class_members.tsx:1:17] 1 │ class Foo { #a; #b; #c; method() { this.#a ? this.#b : this.#c; } } · ── ╰──── + help: Remove the declaration or use it in the code. ⚠ eslint(no-unused-private-class-members): 'c' is defined but never used. ╭─[no_unused_private_class_members.tsx:1:21] 1 │ class Foo { #a; #b; #c; method() { this.#a ? this.#b : this.#c; } } · ── ╰──── + help: Remove the declaration or use it in the code.