Skip to content

lint(unicorn): enable prefer-number-properties, prefer-array-find, prefer-array-index-of - #7516

Merged
nwparker merged 1 commit into
mainfrom
nwparker/lint-number-array-find
Jul 6, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/lint-number-array-find

Conversation

@nwparker

@nwparker nwparker commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Enables three unicorn oxlint rules — one correctness, two performance — and fixes every existing violation repo-wide so they pass as errors. The lasting value is regression-prevention: keeping the next bad isNaN/.filter()[0] from landing.

prefer-number-properties — correctness (76 sites)

  • parseInt/parseFloat/NaN → Number.* (66 sites) — safe aliases, autofixed.
  • isNaN → Number.isNaN (12 sites, hand-converted) — global isNaN coerces its argument (isNaN('x') === true); Number.isNaN does not. I verified every call site already passes a number (Number.parseInt results, number-typed fields/params, Date.getTime()), so the swap is behavior-preserving today and prevents a future non-numeric argument from silently coercing. oxlint deliberately does not autofix these (it respects the semantic gap), so they were done by hand.

prefer-array-find — performance (26 sites)

  • .filter(pred)[0] → .find(pred)
  • .filter(pred).at(-1) / .filter(pred).pop() → .findLast(pred)

Drops the intermediate array and short-circuits (find/findLast stop at the first/last match). Types are preserved (.filter(Boolean).at(-1) and .findLast(Boolean) both yield T | undefined).

prefer-array-index-of — performance/clarity (5 sites)

  • .findIndex(x => x === v) → .indexOf(v).

Runtime-floor checks (this bit matters)

  • mobile/ (extends the root oxlint config, so the rules apply): uses React Native 0.83.9 / Hermes. findLast is ES2023 — confirmed safe because mobile already ships .toReversed() (also ES2023). Number.NaN is universal.
  • config scripts / e2e helpers run on Node 24 — findLast fine.
  • One array-index-of site (AddRepoStartSteps.tsx) compares HTMLButtonElement[] against document.activeElement (Element | null); indexOf needs a runtime-safe as HTMLButtonElement cast there (it only does ===).

Verification

  • pnpm typecheck (node + cli + web) — clean.
  • oxlint (the check CI runs) — clean repo-wide; 0 remaining violations of the three rules.
  • 53 affected test suites pass (1679 tests).

Note: pnpm run lint also reports 2 pre-existing switch-exhaustiveness errors in source-control files from #7461/#7386 — unrelated to this PR, in files it doesn't touch, and not part of the CI lint step (oxlint --format github).

Made with Orca 🐋

…efer-array-index-of

Enable three unicorn rules — one correctness, two performance — and fix every
existing violation repo-wide so the rules pass as errors.

prefer-number-properties (76 sites)
- parseInt/parseFloat/NaN -> Number.* : safe aliases (autofixed).
- isNaN -> Number.isNaN (12 sites, hand-converted): global isNaN coerces its
  argument, Number.isNaN does not. Verified every call site already passes a
  number (Number.parseInt results, number-typed fields, Date.getTime()), so the
  conversion is behavior-preserving today and guards against a future non-numeric
  argument silently coercing.

prefer-array-find (26 sites)
- .filter(pred)[0] -> .find(pred); .filter(pred).at(-1) / .pop() -> .findLast(pred).
  Drops the intermediate array and short-circuits.

prefer-array-index-of (5 sites)
- .findIndex(x => x === v) -> .indexOf(v).

Verified: typecheck (node/cli/web) clean, 53 affected suites pass (1679 tests),
oxlint clean repo-wide. mobile/ uses findLast safely (already ships ES2023
.toReversed()); config scripts and e2e helpers run on Node 24.
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

This PR adds several unicorn/prefer-* lint rules to .oxlintrc.json and applies a broad, mechanical refactor across the codebase to align with them. Global parseInt, parseFloat, isNaN, and NaN usages are replaced with their Number-scoped equivalents (Number.parseInt, Number.parseFloat, Number.isNaN, Number.NaN). Path/array "last non-empty segment" extraction patterns using filter(Boolean).at(-1) or .pop() are replaced with findLast(Boolean), and findIndex calls with simple equality predicates are replaced with indexOf/find. Corresponding test files were updated to match these idiom changes. No functional behavior or exported API signatures were altered.

Sequence Diagram(s)

Not applicable — this change is a mechanical idiom refactor with no new control flow or interaction paths.

Related Issues: None referenced in the provided information.

Related PRs: None referenced in the provided information.

Suggested labels: refactor, lint, chore

Suggested reviewers: None specified.

🐰 A hop through code, both far and wide,
Swapping parseInt for Number's side,
findLast replaces the filter-and-pop dance,
Tidier idioms get their chance,
No new behavior, just cleaner delight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: enabling three unicorn lint rules.
Description check ✅ Passed The description matches the changeset and explains the lint rules and repo-wide fixes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/renderer/src/hooks/useInstalledAgentSkills.ts (1)

47-49: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Duplicate basenameFromPath implementation.

Identical basenameFromPath function exists verbatim in src/renderer/src/lib/orchestration-skill-coverage.ts (lines 63-65). Consider extracting to a shared path utility (e.g. alongside src/shared/cross-platform-path.ts) to avoid drift between the two copies.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 137c66af-0452-41cd-a171-43b0f2ede75a

📥 Commits

Reviewing files that changed from the base of the PR and between 61ecaaf and bece9d5.

📒 Files selected for processing (73)
  • .oxlintrc.json
  • config/scripts/run-electron-vite-dev.mjs
  • config/scripts/verify-release-required-assets.mjs
  • mobile/src/files/mobile-file-preview-route.ts
  • mobile/src/session/mobile-diff-comments.ts
  • mobile/src/session/mobile-terminal-file-tap-open.ts
  • src/main/browser/browser-manager-grab.test.ts
  • src/main/browser/browser-manager.test.ts
  • src/main/browser/cdp-bridge-integration.test.ts
  • src/main/browser/cdp-screenshot.ts
  • src/main/browser/snapshot-engine.test.ts
  • src/main/emulator/android/uiautomator-tree.ts
  • src/main/ghostty/mapper.ts
  • src/main/git/hosted-remote-url.ts
  • src/main/github/client.ts
  • src/main/github/project-view.ts
  • src/main/gitlab/client.ts
  • src/main/ipc/repos.ts
  • src/main/observability/bundle.test.ts
  • src/main/rate-limits/claude-pty.ts
  • src/main/rate-limits/codex-fetcher.ts
  • src/main/rate-limits/gemini-bucket-formatting.ts
  • src/main/rate-limits/gemini-usage-fetcher.test.ts
  • src/main/rate-limits/kimi-fetcher.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/speech/model-manager.ts
  • src/main/ssh/ssh-config-parser.ts
  • src/main/ssh/ssh-g-config-resolution.ts
  • src/main/ssh/ssh-relay-versioned-install.ts
  • src/main/ssh/ssh-remote-platform.ts
  • src/main/ssh/system-ssh-forward-process.ts
  • src/main/startup/dev-instance-identity.ts
  • src/main/updater-prerelease-feed.ts
  • src/main/warp-themes/parser.ts
  • src/relay/agent-hook-server.ts
  • src/relay/git-handler-ops.ts
  • src/relay/git-handler.ts
  • src/relay/port-scan-handler.ts
  • src/relay/pty-handler.ts
  • src/relay/relay.ts
  • src/relay/windows-port-scan.ts
  • src/renderer/src/components/LinearItemDrawer.tsx
  • src/renderer/src/components/Terminal.tsx
  • src/renderer/src/components/github-project/ProjectCell.tsx
  • src/renderer/src/components/native-chat/native-chat-composer-state.ts
  • src/renderer/src/components/native-chat/native-chat-image-paste.ts
  • src/renderer/src/components/right-sidebar/PortsPanel.tsx
  • src/renderer/src/components/settings/SettingsFormControls.tsx
  • src/renderer/src/components/settings/TerminalFontSizeSetting.tsx
  • src/renderer/src/components/settings/ssh-target-draft.ts
  • src/renderer/src/components/settings/ssh-target-save-payload.ts
  • src/renderer/src/components/sidebar/AddRemoteHostDialog.tsx
  • src/renderer/src/components/sidebar/AddRepoStartSteps.tsx
  • src/renderer/src/components/sidebar/WorktreeList.tsx
  • src/renderer/src/components/sidebar/add-repo-dialog-types.ts
  • src/renderer/src/components/sidebar/add-repo-existing-workspaces-telemetry.ts
  • src/renderer/src/components/sidebar/worktree-list-groups.test.ts
  • src/renderer/src/components/stats/share-card-utils.tsx
  • src/renderer/src/components/terminal-pane/layout-serialization.ts
  • src/renderer/src/components/terminal-pane/pty-dispatcher-pi-routing.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.ts
  • src/renderer/src/components/terminal-pane/terminal-appearance.ts
  • src/renderer/src/hooks/useInstalledAgentSkills.ts
  • src/renderer/src/lib/left-sidebar-appearance.ts
  • src/renderer/src/lib/orchestration-skill-coverage.ts
  • src/renderer/src/runtime/sync-runtime-graph.ts
  • src/shared/agent-process-recognition.ts
  • src/shared/cross-platform-path.ts
  • src/shared/linear-links.ts
  • src/shared/localhost-worktree-labels.ts
  • src/shared/terminal-fonts.ts
  • src/shared/worktree-id.ts
  • tests/e2e/helpers/orca-restart.ts

@nwparker
nwparker merged commit ce68722 into main Jul 6, 2026
5 checks passed
@nwparker
nwparker deleted the nwparker/lint-number-array-find branch July 6, 2026 06:56
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…efer-array-index-of (stablyai#7516)

Enable three unicorn rules — one correctness, two performance — and fix every
existing violation repo-wide so the rules pass as errors.

prefer-number-properties (76 sites)
- parseInt/parseFloat/NaN -> Number.* : safe aliases (autofixed).
- isNaN -> Number.isNaN (12 sites, hand-converted): global isNaN coerces its
  argument, Number.isNaN does not. Verified every call site already passes a
  number (Number.parseInt results, number-typed fields, Date.getTime()), so the
  conversion is behavior-preserving today and guards against a future non-numeric
  argument silently coercing.

prefer-array-find (26 sites)
- .filter(pred)[0] -> .find(pred); .filter(pred).at(-1) / .pop() -> .findLast(pred).
  Drops the intermediate array and short-circuits.

prefer-array-index-of (5 sites)
- .findIndex(x => x === v) -> .indexOf(v).

Verified: typecheck (node/cli/web) clean, 53 affected suites pass (1679 tests),
oxlint clean repo-wide. mobile/ uses findLast safely (already ships ES2023
.toReversed()); config scripts and e2e helpers run on Node 24.
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.

1 participant