fix(linter): allow [...new Array(n)] in no-useless-spread (#2124)

closes #1735
This commit is contained in:
Boshen 2024-01-22 17:10:58 +08:00 committed by GitHub
parent fe7c4d09d2
commit d00c44c484
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 1 additions and 16 deletions

View file

@ -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 {
@ -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![
@ -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]);",

View file

@ -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)]