From fd670d542a8062621087cc80a7496b484f79795e Mon Sep 17 00:00:00 2001 From: Boshen Date: Fri, 19 Apr 2024 15:52:41 +0800 Subject: [PATCH] chore(linter): add error message to unicorn/no-single-promise-in-promise-methods --- .../no_single_promise_in_promise_methods.rs | 2 +- .../no_single_promise_in_promise_methods.snap | 102 +++++++++--------- 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/crates/oxc_linter/src/rules/unicorn/no_single_promise_in_promise_methods.rs b/crates/oxc_linter/src/rules/unicorn/no_single_promise_in_promise_methods.rs index 503c9ca94..5cd8b5fdc 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_single_promise_in_promise_methods.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_single_promise_in_promise_methods.rs @@ -12,7 +12,7 @@ use oxc_span::Span; use crate::{ast_util::is_method_call, context::LintContext, rule::Rule, AstNode}; #[derive(Debug, Error, Diagnostic)] -#[error("Wrapping single-element array with `Promise.{1}()` is unnecessary.")] +#[error("eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.{1}()` is unnecessary.")] #[diagnostic( severity(warning), help("Either use the value directly, or switch to `Promise.resolve(…)`.") diff --git a/crates/oxc_linter/src/snapshots/no_single_promise_in_promise_methods.snap b/crates/oxc_linter/src/snapshots/no_single_promise_in_promise_methods.snap index e3380e7a0..5c80fec50 100644 --- a/crates/oxc_linter/src/snapshots/no_single_promise_in_promise_methods.snap +++ b/crates/oxc_linter/src/snapshots/no_single_promise_in_promise_methods.snap @@ -2,224 +2,224 @@ source: crates/oxc_linter/src/tester.rs expression: no_single_promise_in_promise_methods --- - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:15] 1 │ await Promise.all([(0, promise)]) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:39] 1 │ async function * foo() {await Promise.all([yield promise])} · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:39] 1 │ async function * foo() {await Promise.all([yield* promise])} · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:15] 1 │ await Promise.all([() => promise,],) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:15] 1 │ await Promise.all([a ? b : c,],) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:15] 1 │ await Promise.all([x ??= y,],) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:15] 1 │ await Promise.all([x ||= y,],) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:15] 1 │ await Promise.all([x &&= y,],) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:15] 1 │ await Promise.all([x |= y,],) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:15] 1 │ await Promise.all([x ^= y,],) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:15] 1 │ await Promise.all([x ??= y,],) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:15] 1 │ await Promise.all([x ||= y,],) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:15] 1 │ await Promise.all([x &&= y,],) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:15] 1 │ await Promise.all([x | y,],) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:15] 1 │ await Promise.all([x ^ y,],) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:15] 1 │ await Promise.all([x & y,],) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:15] 1 │ await Promise.all([x !== y,],) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:15] 1 │ await Promise.all([x == y,],) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:15] 1 │ await Promise.all([x in y,],) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:15] 1 │ await Promise.all([x >>> y,],) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:15] 1 │ await Promise.all([x + y,],) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:15] 1 │ await Promise.all([x / y,],) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:15] 1 │ await Promise.all([x ** y,],) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:15] 1 │ await Promise.all([promise,],) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:15] 1 │ await Promise.all([getPromise(),],) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:15] 1 │ await Promise.all([promises[0],],) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:15] 1 │ await Promise.all([await promise]) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.any()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.any()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:15] 1 │ await Promise.any([promise]) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.race()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.race()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:15] 1 │ await Promise.race([promise]) · ──── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:15] 1 │ await Promise.all([new Promise(() => {})]) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:16] 1 │ +await Promise.all([+1]) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:2:23] 1 │ 2 │ await Promise.all([(x,y)]) @@ -228,14 +228,14 @@ expression: no_single_promise_in_promise_methods ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:9] 1 │ Promise.all([promise,],) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:3:11] 2 │ foo 3 │ Promise.all([(0, promise),],) @@ -244,7 +244,7 @@ expression: no_single_promise_in_promise_methods ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:3:17] 2 │ foo 3 │ Promise.all([[array][0],],) @@ -253,112 +253,112 @@ expression: no_single_promise_in_promise_methods ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:9] 1 │ Promise.all([promise]).then() · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:9] 1 │ Promise.all([1]).then() · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:9] 1 │ Promise.all([1.]).then() · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:9] 1 │ Promise.all([.1]).then() · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:9] 1 │ Promise.all([(0, promise)]).then() · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:25] 1 │ const _ = () => Promise.all([ a ?? b ,],) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:9] 1 │ Promise.all([ {a} = 1 ,],) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:9] 1 │ Promise.all([ function () {} ,],) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:9] 1 │ Promise.all([ class {} ,],) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:9] 1 │ Promise.all([ new Foo ,],).then() · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:9] 1 │ Promise.all([ new Foo ,],).toString · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:13] 1 │ foo(Promise.all([promise])) · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:9] 1 │ Promise.all([promise]).foo = 1 · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:9] 1 │ Promise.all([promise])[0] ||= 1 · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:9] 1 │ Promise.all([undefined]).then() · ─── ╰──── help: Either use the value directly, or switch to `Promise.resolve(…)`. - ⚠ Wrapping single-element array with `Promise.all()` is unnecessary. + ⚠ eslint-plugin-unicorn(no-single-promise-in-promise-methods): Wrapping single-element array with `Promise.all()` is unnecessary. ╭─[no_single_promise_in_promise_methods.tsx:1:9] 1 │ Promise.all([null]).then() · ───