question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule proposal: `no-new-array`

See original GitHub issue

There is a no-array-constructor rule in core, but it’s not what I want, it enforce Array(1, 2) and new Array(1, 2) to [1, 2],

Fail

const foo = new Array(10);

Pass

const foo = Array.from({length: 10});

Rule should provide suggestions for unknown argument:

const foo = new Array(bar);

Suggestion 1:

const foo = [bar];

Suggestion 2:

const foo = Array.from({length: bar});

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
sindresorhuscommented, Dec 30, 2020

The Array.from trick also has the benefit that it’s the most efficient solution if you need to map over the array afterward as you can do so in one operation:

Array.from({length: 10}, (x, i) => i);
1reaction
silverwindcommented, Dec 23, 2020

Hmm I don’t like this Array.from({length: 10}) because it’s abusing a object to be an arrayLike.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SEC Proposed Rules
SEC Proposed Rules · Regulation NMS: Minimum Pricing Increments, Access Fees, and Transparency of Better Priced Orders · File No: S7-30-22 · Comments...
Read more >
eslint-plugin-unicorn/no-new-array.md at main - GitHub
This rule fills that gap. When using the Array constructor with one argument, it's not clear whether the argument is meant to be...
Read more >
Federal Register/Vol. 87, No. 46/Wednesday, March 9, 2022 ...
ACTION: Proposed rule. SUMMARY: The Securities and Exchange. Commission is proposing new rules under the Investment Advisers Act of.
Read more >
eslint | Yarn - Package Manager
Website | Configuring | Rules | Contributing | Reporting Bugs | Code of Conduct | Twitter | Mailing List | Chat Room. ESLint...
Read more >
Agency Rule List - Spring 2022 - Reginfo.gov
Agency Agenda Stage of Rulemaking RIN SEC Proposed Rule Stage 3235‑AL91 SEC Proposed Rule Stage 3235‑AM06 SEC Proposed Rule Stage 3235‑AM78
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found