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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ working directory: fixtures/overrides_env_globals
: `-- Read-only global 'globalThis' should not be modified.
3 | $ = 'abc';
`----
help: Use a local variable instead of modifying the global 'globalThis'.

! eslint(no-global-assign): Read-only global 'globalThis' should not be modified.
,-[test.js:2:1]
Expand All @@ -23,6 +24,7 @@ working directory: fixtures/overrides_env_globals
: `-- Read-only global 'globalThis' should not be modified.
3 | $ = 'abc';
`----
help: Use a local variable instead of modifying the global 'globalThis'.

! eslint(no-global-assign): Read-only global '$' should not be modified.
,-[test.js:3:1]
Expand All @@ -32,6 +34,7 @@ working directory: fixtures/overrides_env_globals
: `-- Read-only global '$' should not be modified.
4 |
`----
help: Use a local variable instead of modifying the global '$'.

! eslint(no-global-assign): Read-only global 'Foo' should not be modified.
,-[test.js:6:1]
Expand All @@ -40,6 +43,7 @@ working directory: fixtures/overrides_env_globals
: ^|^
: `-- Read-only global 'Foo' should not be modified.
`----
help: Use a local variable instead of modifying the global 'Foo'.

! eslint(no-global-assign): Read-only global 'globalThis' should not be modified.
,-[test.ts:2:1]
Expand All @@ -49,6 +53,7 @@ working directory: fixtures/overrides_env_globals
: `-- Read-only global 'globalThis' should not be modified.
3 | $ = 'abc';
`----
help: Use a local variable instead of modifying the global 'globalThis'.

Found 5 warnings and 0 errors.
Finished in <variable>ms on 3 files with 1 rules using 1 threads.
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_async_promise_executor_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Promise executor functions should not be `async`.").with_label(span)
OxcDiagnostic::warn("Promise executor functions should not be `async`.")
.with_help("Remove the `async` keyword from the Promise executor function.")
.with_label(span)
}

#[derive(Debug, Default, Clone)]
Expand Down
10 changes: 6 additions & 4 deletions crates/oxc_linter/src/rules/eslint/no_class_assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ use oxc_span::Span;
use crate::{context::LintContext, rule::Rule};

fn no_class_assign_diagnostic(name: &str, decl_span: Span, assign_span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("Unexpected re-assignment of class {name}")).with_labels([
decl_span.label(format!("{name} is declared as class here")),
assign_span.label(format!("{name} is re-assigned here")),
])
OxcDiagnostic::warn(format!("Unexpected re-assignment of class {name}"))
.with_help("Use a different variable name instead of re-assigning the class declaration.")
.with_labels([
decl_span.label(format!("{name} is declared as class here")),
assign_span.label(format!("{name} is re-assigned here")),
])
}

#[derive(Debug, Default, Clone)]
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_linter/src/rules/eslint/no_global_assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{

fn no_global_assign_diagnostic(global_name: &str, span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("Read-only global '{global_name}' should not be modified."))
.with_help(format!("Use a local variable instead of modifying the global '{global_name}'."))
.with_label(span.label(format!("Read-only global '{global_name}' should not be modified.")))
}

Expand Down
4 changes: 3 additions & 1 deletion crates/oxc_linter/src/rules/eslint/no_throw_literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ fn no_throw_literal_diagnostic(span: Span, is_undef: bool) -> OxcDiagnostic {
let message =
if is_undef { "Do not throw undefined" } else { "Expected an error object to be thrown" };

OxcDiagnostic::warn(message).with_label(span)
OxcDiagnostic::warn(message)
.with_help("Throwing literals or non-Error objects is not recommended. Use an Error object instead.")
.with_label(span)
}

#[derive(Debug, Default, Clone)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ source: crates/oxc_linter/src/tester.rs
1 │ new Promise(async function foo(resolve, reject) {})
· ─────
╰────
help: Remove the `async` keyword from the Promise executor function.

⚠ eslint(no-async-promise-executor): Promise executor functions should not be `async`.
╭─[no_async_promise_executor.tsx:1:13]
1 │ new Promise(async (resolve, reject) => {})
· ─────
╰────
help: Remove the `async` keyword from the Promise executor function.

⚠ eslint(no-async-promise-executor): Promise executor functions should not be `async`.
╭─[no_async_promise_executor.tsx:1:17]
1 │ new Promise(((((async () => {})))))
· ─────
╰────
help: Remove the `async` keyword from the Promise executor function.
9 changes: 9 additions & 0 deletions crates/oxc_linter/src/snapshots/eslint_no_class_assign.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ source: crates/oxc_linter/src/tester.rs
· │ ╰── A is re-assigned here
· ╰── A is declared as class here
╰────
help: Use a different variable name instead of re-assigning the class declaration.

⚠ eslint(no-class-assign): Unexpected re-assignment of class A
╭─[no_class_assign.tsx:1:7]
Expand All @@ -17,6 +18,7 @@ source: crates/oxc_linter/src/tester.rs
· │ ╰── A is re-assigned here
· ╰── A is declared as class here
╰────
help: Use a different variable name instead of re-assigning the class declaration.

⚠ eslint(no-class-assign): Unexpected re-assignment of class A
╭─[no_class_assign.tsx:1:7]
Expand All @@ -25,6 +27,7 @@ source: crates/oxc_linter/src/tester.rs
· │ ╰── A is re-assigned here
· ╰── A is declared as class here
╰────
help: Use a different variable name instead of re-assigning the class declaration.

⚠ eslint(no-class-assign): Unexpected re-assignment of class A
╭─[no_class_assign.tsx:1:1]
Expand All @@ -33,6 +36,7 @@ source: crates/oxc_linter/src/tester.rs
· │ ╰── A is declared as class here
· ╰── A is re-assigned here
╰────
help: Use a different variable name instead of re-assigning the class declaration.

⚠ eslint(no-class-assign): Unexpected re-assignment of class A
╭─[no_class_assign.tsx:1:7]
Expand All @@ -41,6 +45,7 @@ source: crates/oxc_linter/src/tester.rs
· │ ╰── A is re-assigned here
· ╰── A is declared as class here
╰────
help: Use a different variable name instead of re-assigning the class declaration.

⚠ eslint(no-class-assign): Unexpected re-assignment of class A
╭─[no_class_assign.tsx:1:15]
Expand All @@ -49,6 +54,7 @@ source: crates/oxc_linter/src/tester.rs
· │ ╰── A is re-assigned here
· ╰── A is declared as class here
╰────
help: Use a different variable name instead of re-assigning the class declaration.

⚠ eslint(no-class-assign): Unexpected re-assignment of class A
╭─[no_class_assign.tsx:1:7]
Expand All @@ -57,6 +63,7 @@ source: crates/oxc_linter/src/tester.rs
· │ ╰── A is re-assigned here
· ╰── A is declared as class here
╰────
help: Use a different variable name instead of re-assigning the class declaration.

⚠ eslint(no-class-assign): Unexpected re-assignment of class A
╭─[no_class_assign.tsx:1:7]
Expand All @@ -65,6 +72,7 @@ source: crates/oxc_linter/src/tester.rs
· │ ╰── A is re-assigned here
· ╰── A is declared as class here
╰────
help: Use a different variable name instead of re-assigning the class declaration.

⚠ eslint(no-class-assign): Unexpected re-assignment of class A
╭─[no_class_assign.tsx:1:18]
Expand All @@ -73,3 +81,4 @@ source: crates/oxc_linter/src/tester.rs
· │ ╰── A is re-assigned here
· ╰── A is declared as class here
╰────
help: Use a different variable name instead of re-assigning the class declaration.
Original file line number Diff line number Diff line change
Expand Up @@ -8,59 +8,68 @@ source: crates/oxc_linter/src/tester.rs
· ───┬──
· ╰── Read-only global 'String' should not be modified.
╰────
help: Use a local variable instead of modifying the global 'String'.

⚠ eslint(no-global-assign): Read-only global 'String' should not be modified.
╭─[no_global_assign.tsx:1:1]
1 │ String++;
· ───┬──
· ╰── Read-only global 'String' should not be modified.
╰────
help: Use a local variable instead of modifying the global 'String'.

⚠ eslint(no-global-assign): Read-only global 'Object' should not be modified.
╭─[no_global_assign.tsx:1:3]
1 │ ({Object = 0, String = 0} = {});
· ───┬──
· ╰── Read-only global 'Object' should not be modified.
╰────
help: Use a local variable instead of modifying the global 'Object'.

⚠ eslint(no-global-assign): Read-only global 'String' should not be modified.
╭─[no_global_assign.tsx:1:15]
1 │ ({Object = 0, String = 0} = {});
· ───┬──
· ╰── Read-only global 'String' should not be modified.
╰────
help: Use a local variable instead of modifying the global 'String'.

⚠ eslint(no-global-assign): Read-only global 'top' should not be modified.
╭─[no_global_assign.tsx:1:1]
1 │ top = 0;
· ─┬─
· ╰── Read-only global 'top' should not be modified.
╰────
help: Use a local variable instead of modifying the global 'top'.

⚠ eslint(no-global-assign): Read-only global 'require' should not be modified.
╭─[no_global_assign.tsx:1:1]
1 │ require = 0;
· ───┬───
· ╰── Read-only global 'require' should not be modified.
╰────
help: Use a local variable instead of modifying the global 'require'.

⚠ eslint(no-global-assign): Read-only global 'Object' should not be modified.
╭─[no_global_assign.tsx:1:16]
1 │ function f() { Object = 1; }
· ───┬──
· ╰── Read-only global 'Object' should not be modified.
╰────
help: Use a local variable instead of modifying the global 'Object'.

⚠ eslint(no-global-assign): Read-only global 'a' should not be modified.
╭─[no_global_assign.tsx:1:1]
1 │ a = 1
· ┬
· ╰── Read-only global 'a' should not be modified.
╰────
help: Use a local variable instead of modifying the global 'a'.

⚠ eslint(no-global-assign): Read-only global 'Array' should not be modified.
╭─[no_global_assign.tsx:1:1]
1 │ Array = 1;
· ──┬──
· ╰── Read-only global 'Array' should not be modified.
╰────
help: Use a local variable instead of modifying the global 'Array'.
Loading
Loading