Mmohebifar

javascript-no-useless-spread-unicorn-aligned

Remove semantically redundant spread syntax in array literals, object literals, function calls, and constructor calls when the rewrite is provably behavior-preserving.

javascripttypescriptcleanupeslintspread
Public
0 executions

Run locally

npx codemod javascript-no-useless-spread-unicorn-aligned

javascript-no-useless-spread-unicorn-aligned

Removes semantically redundant spread syntax in JavaScript and TypeScript source, aligned with eslint-plugin-unicorn/no-useless-spread, while staying conservative about runtime behavior.

What It Rewrites

  • Array literals that spread a literal array with no holes, such as const x = [1, ...[2, 3]] to const x = [1, 2, 3]
  • Function and constructor calls that spread a literal array with no holes, such as fn(...[a, b]) to fn(a, b) and new C(...[a, b]) to new C(a, b)
  • Object literals that spread a plain object literal with only static data properties and no key conflicts, such as {x: 0, ...{a: 1}, y: 2} to {x: 0, a: 1, y: 2}

Preserve Cases

  • Sparse arrays such as [...[ ,1]] and [...[, ,]]
  • Non-literal or unknown spread operands such as [...arr], fn(...args), and new C(...factory())
  • Object spreads with getters, setters, methods, computed keys, __proto__, or duplicate-key conflicts
  • Objects with sibling spread properties that are not statically provable as safe to inline

Target Files

  • **/*.{js,mjs,cjs} via the JavaScript parser
  • **/*.ts via the TypeScript parser
  • **/*.{jsx,tsx} via the TSX parser

Default exclusions: **/node_modules/**, **/dist/**, **/build/**, **/coverage/**, **/vendor/**, **/*.test.*, **/*.spec.*, **/test/**, **/tests/**, **/__tests__/**, **/__mocks__/**, **/*.config.*, and **/*.example.*

Usage

bash

Development

bash

License

MIT

Ready to contribute?

Build your own codemod and share it with the community.