Repository navigation
lint(unicorn): enable prefer-number-properties, prefer-array-find, prefer-array-index-of - #7516
Conversation
…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.
📝 WalkthroughWalkthroughChangesThis PR adds several 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, 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/hooks/useInstalledAgentSkills.ts (1)
47-49: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueDuplicate
basenameFromPathimplementation.Identical
basenameFromPathfunction exists verbatim insrc/renderer/src/lib/orchestration-skill-coverage.ts(lines 63-65). Consider extracting to a shared path utility (e.g. alongsidesrc/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
📒 Files selected for processing (73)
.oxlintrc.jsonconfig/scripts/run-electron-vite-dev.mjsconfig/scripts/verify-release-required-assets.mjsmobile/src/files/mobile-file-preview-route.tsmobile/src/session/mobile-diff-comments.tsmobile/src/session/mobile-terminal-file-tap-open.tssrc/main/browser/browser-manager-grab.test.tssrc/main/browser/browser-manager.test.tssrc/main/browser/cdp-bridge-integration.test.tssrc/main/browser/cdp-screenshot.tssrc/main/browser/snapshot-engine.test.tssrc/main/emulator/android/uiautomator-tree.tssrc/main/ghostty/mapper.tssrc/main/git/hosted-remote-url.tssrc/main/github/client.tssrc/main/github/project-view.tssrc/main/gitlab/client.tssrc/main/ipc/repos.tssrc/main/observability/bundle.test.tssrc/main/rate-limits/claude-pty.tssrc/main/rate-limits/codex-fetcher.tssrc/main/rate-limits/gemini-bucket-formatting.tssrc/main/rate-limits/gemini-usage-fetcher.test.tssrc/main/rate-limits/kimi-fetcher.tssrc/main/runtime/orca-runtime.tssrc/main/speech/model-manager.tssrc/main/ssh/ssh-config-parser.tssrc/main/ssh/ssh-g-config-resolution.tssrc/main/ssh/ssh-relay-versioned-install.tssrc/main/ssh/ssh-remote-platform.tssrc/main/ssh/system-ssh-forward-process.tssrc/main/startup/dev-instance-identity.tssrc/main/updater-prerelease-feed.tssrc/main/warp-themes/parser.tssrc/relay/agent-hook-server.tssrc/relay/git-handler-ops.tssrc/relay/git-handler.tssrc/relay/port-scan-handler.tssrc/relay/pty-handler.tssrc/relay/relay.tssrc/relay/windows-port-scan.tssrc/renderer/src/components/LinearItemDrawer.tsxsrc/renderer/src/components/Terminal.tsxsrc/renderer/src/components/github-project/ProjectCell.tsxsrc/renderer/src/components/native-chat/native-chat-composer-state.tssrc/renderer/src/components/native-chat/native-chat-image-paste.tssrc/renderer/src/components/right-sidebar/PortsPanel.tsxsrc/renderer/src/components/settings/SettingsFormControls.tsxsrc/renderer/src/components/settings/TerminalFontSizeSetting.tsxsrc/renderer/src/components/settings/ssh-target-draft.tssrc/renderer/src/components/settings/ssh-target-save-payload.tssrc/renderer/src/components/sidebar/AddRemoteHostDialog.tsxsrc/renderer/src/components/sidebar/AddRepoStartSteps.tsxsrc/renderer/src/components/sidebar/WorktreeList.tsxsrc/renderer/src/components/sidebar/add-repo-dialog-types.tssrc/renderer/src/components/sidebar/add-repo-existing-workspaces-telemetry.tssrc/renderer/src/components/sidebar/worktree-list-groups.test.tssrc/renderer/src/components/stats/share-card-utils.tsxsrc/renderer/src/components/terminal-pane/layout-serialization.tssrc/renderer/src/components/terminal-pane/pty-dispatcher-pi-routing.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.tssrc/renderer/src/components/terminal-pane/terminal-appearance.tssrc/renderer/src/hooks/useInstalledAgentSkills.tssrc/renderer/src/lib/left-sidebar-appearance.tssrc/renderer/src/lib/orchestration-skill-coverage.tssrc/renderer/src/runtime/sync-runtime-graph.tssrc/shared/agent-process-recognition.tssrc/shared/cross-platform-path.tssrc/shared/linear-links.tssrc/shared/localhost-worktree-labels.tssrc/shared/terminal-fonts.tssrc/shared/worktree-id.tstests/e2e/helpers/orca-restart.ts
…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.
Enables three
unicornoxlint 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 badisNaN/.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) — globalisNaNcoerces its argument (isNaN('x') === true);Number.isNaNdoes not. I verified every call site already passes a number (Number.parseIntresults,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 yieldT | undefined).prefer-array-index-of— performance/clarity (5 sites).findIndex(x => x === v)→.indexOf(v).Runtime-floor checks (this bit matters)
extendsthe root oxlint config, so the rules apply): uses React Native 0.83.9 / Hermes.findLastis ES2023 — confirmed safe because mobile already ships.toReversed()(also ES2023).Number.NaNis universal.findLastfine.array-index-ofsite (AddRepoStartSteps.tsx) comparesHTMLButtonElement[]againstdocument.activeElement(Element | null);indexOfneeds a runtime-safeas HTMLButtonElementcast 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.Note:
pnpm run lintalso reports 2 pre-existingswitch-exhaustivenesserrors insource-controlfiles 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 🐋