Skip to content

Commit

Permalink
fix(linter): allow [...new Array(n)] in no-useless-spread (#2124)
Browse files Browse the repository at this point in the history
closes #1735
  • Loading branch information
Boshen authored Jan 22, 2024
1 parent fe7c4d0 commit d00c44c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 16 deletions.
10 changes: 1 addition & 9 deletions crates/oxc_linter/src/rules/unicorn/no_useless_spread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,6 @@ fn check_useless_array_clone<'a>(array_expr: &ArrayExpression<'a>, ctx: &LintCon
));
}
}

if let Expression::NewExpression(new_expr) = &spread_elem.argument {
if !is_new_expression(new_expr, &["Array"], None, None) {
return;
}

ctx.diagnostic(NoUselessSpreadDiagnostic::CloneArray(span, "new Array".into()));
}
}

fn is_single_array_spread(node: &ArrayExpression) -> bool {
Expand Down Expand Up @@ -465,6 +457,7 @@ fn test() {
r"[...Promise.all(foo)]",
r"[...Promise.allSettled(foo)]",
r"[...await Promise.all(foo, extraArgument)]",
r"[...new Array(3)]",
];

let fail = vec![
Expand Down Expand Up @@ -558,7 +551,6 @@ fn test() {
r"[...Object.values(foo)]",
r"[...Array.from(foo)]",
r"[...Array.of()]",
r"[...new Array(3)]",
r"[...await Promise.all(foo)]",
r"[...await Promise.allSettled(foo)]",
r"for (const foo of[...iterable]);",
Expand Down
7 changes: 0 additions & 7 deletions crates/oxc_linter/src/snapshots/no_useless_spread.snap
Original file line number Diff line number Diff line change
Expand Up @@ -666,13 +666,6 @@ expression: no_useless_spread
╰────
help: `Array.of` returns a new array. Spreading it into an array expression to create a new array is redundant.

eslint-plugin-unicorn(no-useless-spread): Using a spread operator here creates a new array unnecessarily.
╭─[no_useless_spread.tsx:1:1]
1 │ [...new Array(3)]
· ───
╰────
help: `new Array` returns a new array. Spreading it into an array expression to create a new array is redundant.

eslint-plugin-unicorn(no-useless-spread): Using a spread operator here creates a new array unnecessarily.
╭─[no_useless_spread.tsx:1:1]
1 │ [...await Promise.all(foo)]
Expand Down

0 comments on commit d00c44c

Please sign in to comment.