feat(linter): promote no-new-array to correctness with better help message (#2123)

relates #1735
This commit is contained in:
Boshen 2024-01-22 16:57:57 +08:00 committed by GitHub
parent 20a34b5294
commit d90db3afe0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 171 additions and 115 deletions

View file

@ -9,8 +9,8 @@ use oxc_span::Span;
use crate::{context::LintContext, rule::Rule, AstNode};
#[derive(Debug, Error, Diagnostic)]
#[error("eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.")]
#[diagnostic(severity(warning), help(r#"If the argument is the array's length, consider using `Array.from({{ length: n }})` instead. If the argument is the only element, use `[element]` instead."#))]
#[error("eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.")]
#[diagnostic(severity(warning), help(r#"It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({{ length: n }})`. If the argument is the only element, use `[element]`."#))]
struct NoNewArrayDiagnostic(#[label] pub Span);
#[derive(Debug, Default, Clone)]
@ -37,7 +37,7 @@ declare_oxc_lint!(
/// const array = [42];
/// ```
NoNewArray,
suspicious
correctness
);
impl Rule for NoNewArray {

View file

@ -2,396 +2,452 @@
source: crates/oxc_linter/src/tester.rs
expression: no_new_array
---
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ const array = new Array(1)
· ────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ const array = new Array(1.5)
· ──────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ const array = new Array(Number("1"))
· ──────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ const array = new Array("1")
· ──────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ const array = new Array(null)
· ───────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ const array = new Array(("1"))
· ────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ const array = new Array((0, 1))
· ─────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(0xff)
· ───────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(Math.PI | foo)
· ────────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(Math.min(foo, bar))
· ─────────────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(Number(foo))
· ──────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(Number.MAX_SAFE_INTEGER)
· ──────────────────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(parseInt(foo))
· ────────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(Number.parseInt(foo))
· ───────────────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(+foo)
· ───────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(-Math.PI)
· ───────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(-"-2")
· ────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(foo.length)
· ─────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ const foo = 1; new Array(foo + 2)
· ──────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(foo - 2)
· ──────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(foo -= 2)
· ───────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(foo ? 1 : 2)
· ──────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ const truthy = "truthy"; new Array(truthy ? 1 : foo)
· ───────────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ const falsy = !"truthy"; new Array(falsy ? foo : 1)
· ──────────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array((1n, 2))
· ──────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(Number.NaN)
· ─────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(NaN)
· ──────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(foo >>> bar)
· ──────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(foo >>>= bar)
· ───────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(++bar.length)
· ───────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(bar.length++)
· ───────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(foo = bar.length)
· ───────────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array("0xff")
· ─────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(Math.NON_EXISTS_PROPERTY)
· ───────────────────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(Math.NON_EXISTS_METHOD(foo))
· ──────────────────────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(Math[min](foo, bar))
· ──────────────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(Number[MAX_SAFE_INTEGER])
· ───────────────────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(new Number(foo))
· ──────────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ const foo = 1; new Array(foo + "2")
· ────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(foo - 2n)
· ───────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(foo -= 2n)
· ────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(foo instanceof 1)
· ───────────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(foo || 1)
· ───────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(foo ||= 1)
· ────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(foo ? 1n : 2)
· ───────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array((1, 2n))
· ──────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(-foo)
· ───────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(~foo)
· ───────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(typeof 1)
· ───────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ const truthy = "truthy"; new Array(truthy ? foo : 1)
· ───────────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ const falsy = !"truthy"; new Array(falsy ? 1 : foo)
· ──────────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(unknown ? foo : 1)
· ────────────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(unknown ? 1 : foo)
· ────────────────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ new Array(++foo)
· ────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ const array = new Array(foo)
· ──────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.
⚠ eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.
╭─[no_new_array.tsx:1:1]
1 │ const array = new Array(length)
· ─────────────────
╰────
help: If the argument is the array's length, consider using `Array.from({ length: n })` instead. If the argument is the only element, use `[element]` instead.
help: It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({ length: n })`. If the
argument is the only element, use `[element]`.