fix(linter) improve span for no-unneccessary-await (#1732)

closes #1718
This commit is contained in:
Cameron 2023-12-18 13:34:28 +00:00 committed by GitHub
parent 78931e6187
commit f1d1563cde
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 40 deletions

View file

@ -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![

View file

@ -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 (<a></a>)
· ───────────────
· ─────
╰────
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`