oxc-project/oxc · error · OxcDiagnostic

Wrapping single-element array with `Promise.{method_name}()`

Error message

Wrapping single-element array with `Promise.{method_name}()` is unnecessary.

What it means

Raised by unicorn/no-single-promise-in-promise-methods when `Promise.all([x])`, `Promise.allSettled([x])`, etc. is given an array with exactly one element. The method name is interpolated into the message; the faulting input is the single-element array passed to the Promise method at the labeled span.

Source

Thrown at crates/oxc_linter/src/rules/unicorn/no_single_promise_in_promise_methods.rs:13

use oxc_ast::{
    AstKind,
    ast::{CallExpression, Expression},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_semantic::NodeId;
use oxc_span::{GetSpan, Span};

use crate::{AstNode, ast_util::is_method_call, context::LintContext, rule::Rule};

fn no_single_promise_in_promise_methods_diagnostic(span: Span, method_name: &str) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!(
        "Wrapping single-element array with `Promise.{method_name}()` is unnecessary."
    ))
    .with_help("Either use the value directly, or switch to `Promise.resolve(…)`.")
    .with_label(span)
}

#[derive(Debug, Default, Clone)]
pub struct NoSinglePromiseInPromiseMethods;

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Disallow passing single-element arrays to `Promise` methods.
    ///
    /// ### Why is this bad?
    ///
    /// Passing a single-element array to `Promise.all()`, `Promise.any()`, or
    /// `Promise.race()` is likely a mistake.

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Await the value directly if it is already a promise
  2. Use `Promise.resolve(value)` when a promise is required
  3. Add the other concurrent operations to the array if they were intended
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/unicorn/no_single_promise_in_promise_methods.rs:13 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/d6dee1d9a70de64a. Report an issue: GitHub.