diff --git a/crates/oxc_linter/src/rules/unicorn/no_unnecessary_await.rs b/crates/oxc_linter/src/rules/unicorn/no_unnecessary_await.rs index 2a39160f5..038352ad0 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_unnecessary_await.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_unnecessary_await.rs @@ -56,13 +56,19 @@ impl Rule for NoUnnecessaryAwait { } }) } { - ctx.diagnostic(NoUnnecessaryAwaitDiagnostic(expr.span)); + ctx.diagnostic(NoUnnecessaryAwaitDiagnostic(Span::new( + expr.span.start, + expr.span.start + 5, + ))); } else { - ctx.diagnostic_with_fix(NoUnnecessaryAwaitDiagnostic(expr.span), || { - let mut formatter = ctx.formatter(); - expr.argument.gen(&mut formatter); - Fix::new(formatter.into_code(), expr.span) - }); + ctx.diagnostic_with_fix( + NoUnnecessaryAwaitDiagnostic(Span::new(expr.span.start, expr.span.start + 5)), + || { + let mut formatter = ctx.formatter(); + expr.argument.gen(&mut formatter); + Fix::new(formatter.into_code(), expr.span) + }, + ); }; } } @@ -145,6 +151,8 @@ fn test() { ("async function foo() {+await +1}", None), ("async function foo() {-await-1}", None), ("async function foo() {+await -1}", None), + // https://github.com/oxc-project/oxc/issues/1718 + ("await await this.assertTotalDocumentCount(expectedFormattedTotalDocCount);", None), ]; let fix = vec![ diff --git a/crates/oxc_linter/src/snapshots/no_unnecessary_await.snap b/crates/oxc_linter/src/snapshots/no_unnecessary_await.snap index f782414d2..c3cdad499 100644 --- a/crates/oxc_linter/src/snapshots/no_unnecessary_await.snap +++ b/crates/oxc_linter/src/snapshots/no_unnecessary_await.snap @@ -5,238 +5,245 @@ expression: no_unnecessary_await ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await [] - · ──────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await [Promise.resolve()] - · ───────────────────────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await (() => {}) - · ──────────────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await (() => Promise.resolve()) - · ─────────────────────────────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await (a === b) - · ─────────────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await (a instanceof Promise) - · ──────────────────────────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await (a > b) - · ───────────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await class {} - · ────────────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await class extends Promise {} - · ────────────────────────────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await function() {} - · ─────────────────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await function name() {} - · ──────────────────────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await function() { return Promise.resolve() } - · ───────────────────────────────────────────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await (<>) - · ───────────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await () - · ─────────────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await 0 - · ─────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await 1 - · ─────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await "" - · ──────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await "string" - · ────────────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await true - · ────────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await false - · ─────────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await null - · ────────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await 0n - · ──────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await 1n - · ──────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await `${Promise.resolve()}` - · ──────────────────────────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await !Promise.resolve() - · ──────────────────────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await void Promise.resolve() - · ──────────────────────────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await +Promise.resolve() - · ──────────────────────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await ~1 - · ──────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await ++foo - · ─────────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await foo-- - · ─────────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ await (Promise.resolve(), 1) - · ──────────────────────────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ async function foo() {+await +1} - · ──────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ async function foo() {-await-1} - · ─────── + · ───── ╰──── help: consider to remove the `await` ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values ╭─[no_unnecessary_await.tsx:1:1] 1 │ async function foo() {+await -1} - · ──────── + · ───── + ╰──── + help: consider to remove the `await` + + ⚠ eslint-plugin-unicorn(no-unnecessary-await): Disallow awaiting non-promise values + ╭─[no_unnecessary_await.tsx:1:1] + 1 │ await await this.assertTotalDocumentCount(expectedFormattedTotalDocCount); + · ───── ╰──── help: consider to remove the `await`