Skip to content

feat(unicorn): add no-array-reverse rule - #2198

Merged
elecmonkey merged 3 commits into
web-infra-dev:mainfrom
HashemKhalifa:feat/unicorn-no-array-reverse
Sep 18, 2026
Merged

elecmonkey merged 3 commits into
web-infra-dev:mainfrom
HashemKhalifa:feat/unicorn-no-array-reverse

Conversation

@HashemKhalifa

Copy link
Copy Markdown
Contributor

Motivation

Refs #1309.

Port unicorn/no-array-reverse from eslint-plugin-unicorn v75.0.0. Verified that the rule was absent from main and exact-name PR searches returned no matches, including immediately before publication.

Changes

  • Add suggestion-only Array#toReversed() replacements and the upstream allowExpressionStatement option (default true).
  • Preserve spread-copy alternatives, parentheses and optional member access; exclude optional calls, computed names and known non-array receivers consistently with the upstream cases.
  • Share suggestion construction through a reusable array-mutation helper. This PR is self-contained against main.
  • Register the rule, option schema and JavaScript mirror, with focused documentation.

Verification completed locally

  • 25 upstream/documentation cases and 35 additional AST/semantic cases. Go assertions check message IDs/text, full ranges, applied autofixes and suggestion IDs/outputs against the pinned upstream results.
  • Representative edit-demand tests cover diagnostics-only, autofix-only, suggestion-only and all-edit consumers, with stable diagnostic identity and no edits produced for unrequested categories.
  • Focused Go 1.26.0 tests passed: go test ./internal/plugins/unicorn/rules/no_array_reverse ./internal/plugins/unicorn/unicornutil.
  • Diff-aware golangci-lint 2.12.2 passed for the changed Go packages, including the catalog and affected helper consumers.
  • Changed-file spelling, root pnpm run format:check, and git diff --check passed. Normal repository commit hooks remain enabled.

Validation not completed locally

The full catalog test reached linking, but the Mac encountered disk pressure and sustained linker memory/I/O pressure. Those full-build jobs were stopped; no catalog-test pass is claimed.

Fresh native/core JavaScript builds, the JavaScript integration mirror, and the additional native-API differential run have not completed locally. The JS mirror is included but is not claimed as passing. CI should validate the native/JavaScript integration before merge.

@elecmonkey elecmonkey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As with #2199 & #2200, please add this rule to the recommended rules list. I found no other issues.

Enable unicorn/no-array-reverse at error severity in the existing recommended
preset and assert its public preset registration in the existing test suite.

Verified the selected source-backed preset test, unchanged sibling settings,
upstream severity, formatting, spelling, and diff checks.
elecmonkey
elecmonkey previously approved these changes Sep 17, 2026
@elecmonkey
elecmonkey merged commit 1722a92 into web-infra-dev:main Sep 18, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants