Disallow Array constructors

Proprietary

Replaces Array() and new Array() calls with the equivalent array literal, e.g. new Array(0, 1, 2) becomes [0, 1, 2]. The call is only replaced when the literal is provably equivalent: zero arguments, or at least two non-spread arguments, so the sparse-array behavior of a single numeric argument is impossible. A semicolon is prepended when the previous statement would otherwise continue into the new literal. Replicates the autofix of the ESLint rule no-array-constructor under its default options.

org.openrewrite.javascript.cleanup.NoArrayConstructor
mod run . --recipe=org.openrewrite.javascript.cleanup.NoArrayConstructor

Install it once, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.