Skip to content

fix: correct error message in useIndexOf rule#7234

Merged
siketyan merged 6 commits intobiomejs:mainfrom
JeetuSuthar:main
Aug 16, 2025
Merged

fix: correct error message in useIndexOf rule#7234
siketyan merged 6 commits intobiomejs:mainfrom
JeetuSuthar:main

Conversation

@JeetuSuthar
Copy link
Contributor

Fixes #7233

The error message was incorrectly suggesting to prefer findIndex() over indexOf(), when it should suggest the opposite. Updated the diagnostic message to correctly recommend using indexOf()/lastIndexOf() over findIndex()/findLastIndex().

Summary

Fixed incorrect error message in the useIndexOf lint rule. The diagnostic was showing "Prefer Array#findIndex() over Array#indexOf()" when it should show "Prefer Array#indexOf() over Array#findIndex()". This was a simple variable swap in the diagnostic message template.

Test Plan

The fix swaps two variables in the diagnostic message string. The existing test snapshots will catch this change and verify the message is now correct. GitHub CI will validate the build and tests.

Fixes biomejs#7233

The error message was incorrectly suggesting to prefer findIndex() over indexOf(),
when it should suggest the opposite. Updated the diagnostic message to correctly
recommend using indexOf()/lastIndexOf() over findIndex()/findLastIndex().
@changeset-bot
Copy link

changeset-bot bot commented Aug 15, 2025

🦋 Changeset detected

Latest commit: 9d78a13

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 15, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The PR updates the diagnostic text in crates/biome_js_analyze/src/lint/complexity/use_index_of.rs to state a preference for Array#indexOf/lastIndexOf over Array#findIndex/findLastIndex when looking for the index of an item. Only the diagnostic wording and punctuation were changed; no logic, control flow or public signatures were modified.

Assessment against linked issues

Objective Addressed Explanation
Fix incorrect diagnostic message for complexity/useIndexOf to prefer Array#findIndex() over Array#indexOf() (#7233) The change makes the diagnostic prefer indexOf/lastIndexOf over findIndex/findLastIndex, which is the opposite of the requested fix.

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2ac0339 and 9d78a13.

📒 Files selected for processing (1)
  • .changeset/slimy-zoos-search.md (1 hunks)
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages labels Aug 15, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 8d5ed69 and 622dd23.

📒 Files selected for processing (1)
  • crates/biome_js_analyze/src/lint/complexity/use_index_of.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{rs,toml}

📄 CodeRabbit Inference Engine (CLAUDE.md)

Format code (Rust + TOML) using just format

Format Rust and TOML files before committing (use just f/just format).

Files:

  • crates/biome_js_analyze/src/lint/complexity/use_index_of.rs
crates/biome_*/**/*

📄 CodeRabbit Inference Engine (CLAUDE.md)

Core crates must be located in /crates/biome_*/

Files:

  • crates/biome_js_analyze/src/lint/complexity/use_index_of.rs
🔇 Additional comments (1)
crates/biome_js_analyze/src/lint/complexity/use_index_of.rs (1)

178-182: Diagnostic wording now matches rule intent (indexOf over findIndex).

Swapping new_member_name/old_member_name fixes the message to prefer indexOf/lastIndexOf over findIndex/findLastIndex. The note text and the action (Lines 214–215) remain consistent with this change. Docs at Lines 17–23 also align. Nice tidy fix.

Comment on lines +178 to 179
"Prefer "<Emphasis>"Array#"{new_member_name}"()"</Emphasis>" over "<Emphasis>"Array#"{old_member_name}"()"</Emphasis>" when looking for the index of an item."
},
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify snapshots and references to the old phrasing.

To be safe, scan for any stale snapshots or docs still asserting the old message text and update them if needed. Also, please run the formatter as per repo conventions.

Run this from the repo root:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Searching for old, now-incorrect diagnostics…"
rg -n -C2 -P 'Prefer\s+Array#find(Index|LastIndex)\(\)\s+over\s+Array#(last)?indexOf\(\)'

echo
echo "Searching for the new, correct diagnostics…"
rg -n -C2 -P 'Prefer\s+Array#(last)?indexOf\(\)\s+over\s+Array#find(Last)?Index\(\)'

echo
echo "Reminder: format Rust/TOML before commit:"
echo "  just format"

Length of output: 3517


Update stale snapshots & run formatter

The snapshots under crates/biome_js_analyze/tests/specs/complexity/useIndexOf/invalid.js.snap still contain the old message:

i Prefer Array#findIndex() over Array#indexOf() when looking for the index of an item.

Please update those lines to:

i Prefer Array#indexOf() over Array#findIndex() when looking for the index of an item.

Then run:

just format

🤖 Prompt for AI Agents
In crates/biome_js_analyze/src/lint/complexity/use_index_of.rs around lines
178-179, the emitted message text was inverted; update the snapshot(s) under
crates/biome_js_analyze/tests/specs/complexity/useIndexOf/invalid.js.snap to
replace the old line "i Prefer Array#findIndex() over Array#indexOf() when
looking for the index of an item." with "i Prefer Array#indexOf() over
Array#findIndex() when looking for the index of an item." and then run the
formatter with the command `just format`.

@ematipico
Copy link
Member

Thank you @JeetuSuthar

This change will trigger the update of testing snapshots. Can you please update them? The contribution guide explains how

Updated test snapshots to reflect the corrected error message that now
properly suggests using indexOf()/lastIndexOf() over findIndex()/findLastIndex().
@JeetuSuthar
Copy link
Contributor Author

@ematipico Thank you for the guidance! I've updated the test snapshots in the latest commit. The snapshots now reflect the corrected error message that properly suggests using indexOf()/lastIndexOf() over findIndex()/findLastIndex().

Changes made:

  • Fixed the diagnostic message in the rule implementation
  • Updated all test snapshots to show the correct error messages

@codspeed-hq
Copy link

codspeed-hq bot commented Aug 15, 2025

CodSpeed Performance Report

Merging #7234 will not alter performance

Comparing JeetuSuthar:main (2ac0339) with main (8d5ed69)1

Summary

✅ 131 untouched benchmarks

Footnotes

  1. No successful run was found on main (c63026e) during the generation of this report, so 8d5ed69 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Remove extra backticks at the end of error messages in the test snapshots
to match the exact format expected by the test runner.
@ematipico
Copy link
Member

Thank you. One last thing is the changelog, as the bot showed. The contribution guide shows everything

@JeetuSuthar
Copy link
Contributor Author

@ematipico
Thank you! I understood
Appreciate your guidance!

@JeetuSuthar
Copy link
Contributor Author

@ematipico
Just to confirm : Based on the contributing guide stating "Our changesets should be about user-facing changes. Internal changes don't need changesets," I believe this error message fix doesn't require one since it's an internal improvement, not a new feature or breaking change.

Should I proceed without a changeset, or would you prefer one for this fix?

@siketyan
Copy link
Member

@JeetuSuthar Fixing an error message is still an user-facing change, as users can observe the diagnostic message has been changed. So we would prefer adding a changeset.

@JeetuSuthar
Copy link
Contributor Author

@siketyan I apologize for the confusion earlier. I've now added the changeset as requested.

Copy link
Member

@siketyan siketyan left a comment

Choose a reason for hiding this comment

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

Thank you!

@siketyan siketyan merged commit b7aa111 into biomejs:main Aug 16, 2025
2 of 3 checks passed
@github-actions github-actions bot mentioned this pull request Aug 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Linter Area: linter L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

💅 Wrong error message - useIndexOf

3 participants