Skip to content

[eslint-miner] Add ESLint rule: no-math-minmax-array-spread #53633

Description

@github-actions

Summary

New custom ESLint rule: no-math-minmax-array-spread

Flags Math.max(...expr) / Math.min(...expr) calls where the sole argument is a spread of a non-literal expression (identifier, member expression, or call expression). Spreading a large array into call arguments can throw RangeError: Maximum call stack size exceeded — a real, well-known JS engine limitation (commonly tens of thousands of elements, engine/version dependent).

Evidence (recurring pattern in actions/setup/js)

Running the new rule against actions/setup/js surfaces 3 real, previously-unflagged instances:

  • actions/setup/js/daily_aic_workflow_helpers.cjs:208-209Math.min(...values) / Math.max(...values) where values is built from runs.map(...).filter(...) — size depends on external workflow-run data (unbounded).
  • actions/setup/js/data_schema_normalizer.cjs (per lint output) and actions/setup/js/patch_path_helpers.cjs:28Math.min(...foundSeparatorIndices).

No existing rule in eslint-factory/src/rules covers this pattern (checked all ~50 rules first).

Design / false-positive avoidance

  • Only flags the single-argument spread form (Math.max(...arr)). Mixed forms like Math.max(0, ...arr) or Math.max(a, b, ...arr) are left alone, since fixed literal arguments suggest an intentional, likely-bounded call shape.
  • Spreading an inline array literal (Math.max(...[1, 2, 3])) is never flagged — its size is statically bounded by the source itself.
  • Skips calls where Math is shadowed by a local declaration.
  • Message includes the concrete fix: arr.reduce((a, b) => Math.max(a, b)).

Validation

  • cd eslint-factory && npm install
  • cd eslint-factory && npm run build — passes, no TS errors.
  • npx vitest run — full suite passes: 614/614 tests (including 8 new tests for this rule, valid + invalid cases).
  • npm run lint:setup-js — new rule fires correctly on the 3 real instances above; no new warnings/errors introduced elsewhere.

Files changed

  • eslint-factory/src/rules/no-math-minmax-array-spread.ts (new rule)
  • eslint-factory/src/rules/no-math-minmax-array-spread.test.ts (new tests)
  • eslint-factory/src/index.ts (register rule in plugin)
  • eslint-factory/eslint.config.cjs (enable rule as warn)
  • eslint-factory/README.md (document rule + add to rule index table)

Scope is limited to eslint-factory/**; no changes outside eslint-factory or actions/setup/js scanning targets.


Warning

Protected Files — Push Permission Denied

This was originally intended as a pull request, but the patch modifies protected files. A human must create the pull request manually.

Protected files
  • README.md

The push was rejected because GitHub Actions does not have workflows permission to push these changes, and is never allowed to make such changes, or other authorization being used does not have this permission.

Create the pull request manually
# Download the patch from the workflow run
gh run download 32118635277 -n agent -D /tmp/agent-32118635277

# Create a new branch
git checkout -b eslint-miner/no-math-minmax-array-spread-451d131a8aae98d1 main

# Apply the patch (--3way handles cross-repo patches)
git am --3way /tmp/agent-32118635277/aw-eslint-miner-no-math-minmax-array-spread.patch

# Push the branch and create the pull request
git push origin eslint-miner/no-math-minmax-array-spread-451d131a8aae98d1
gh pr create --title '[eslint-miner] Add ESLint rule: no-math-minmax-array-spread' --base main --head eslint-miner/no-math-minmax-array-spread-451d131a8aae98d1 --repo github/gh-aw

Generated by ESLint Miner · auto · 235.6 AIC · ⌖ 11.8 AIC · ⊞ 6.8K ·

  • expires on Aug 25, 2026, 1:11 AM UTC-08:00

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions