Skip to content

Conversation

@Netail
Copy link
Member

@Netail Netail commented Nov 14, 2025

Summary

Implement Eslint's prefer-find

Closes #7655

Test Plan

Docs

@changeset-bot
Copy link

changeset-bot bot commented Nov 14, 2025

🦋 Changeset detected

Latest commit: af1a98a

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

@github-actions github-actions bot added A-CLI Area: CLI A-Project Area: project A-Linter Area: linter L-JavaScript Language: JavaScript and super languages A-Diagnostic Area: diagnostocis A-Type-Inference Area: type inference labels Nov 14, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 14, 2025

Walkthrough

Adds a new nursery lint rule useFind that flags patterns using Array.prototype.filter() followed by index access ([0] or .at(0)) and suggests Array.prototype.find(). Introduces rule implementation and metadata, tests for valid and invalid cases, and a new UseFindOptions config type. Exposes the use_find module in rule options. Also adds a new Type::is_bigint_literal(&self, value: i64) -> bool predicate — accidentally duplicated twice in the same file.

Suggested reviewers

  • dyc3
  • ematipico

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(js_analyze): implement useFind' clearly and concisely describes the main change—implementing the useFind lint rule for JavaScript analysis.
Linked Issues check ✅ Passed The PR successfully implements the useFind rule as requested in issue #7655, porting the prefer-find rule from typescript-eslint with all necessary components including rule logic, tests, and type utilities.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing the useFind rule: the new lint rule, helper utilities, test cases, and configuration—no unrelated modifications detected.
Description check ✅ Passed The PR description directly addresses the changeset by referencing ESLint's prefer-find rule and closing a related issue.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

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

🧹 Nitpick comments (1)
crates/biome_js_analyze/src/lint/nursery/use_find.rs (1)

106-119: Minor: Clarify diagnostic message.

The diagnostic message on Line 112 says "Array#filter[0]", which might be confused with computed member access. Consider "Array#filter()[0]" to be clearer.

Apply this diff:

             markup! {
-                "Prefer using Array#find() over Array#filter[0]."
+                "Prefer using Array#find() over Array#filter()[0]."
             },
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1fdcaf0 and 3d75efe.

⛔ Files ignored due to path filters (9)
  • crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rs is excluded by !**/migrate/eslint_any_rule_to_biome.rs and included by **
  • crates/biome_configuration/src/analyzer/linter/rules.rs is excluded by !**/rules.rs and included by **
  • crates/biome_configuration/src/generated/domain_selector.rs is excluded by !**/generated/**, !**/generated/** and included by **
  • crates/biome_diagnostics_categories/src/categories.rs is excluded by !**/categories.rs and included by **
  • crates/biome_js_analyze/src/lint/nursery.rs is excluded by !**/nursery.rs and included by **
  • crates/biome_js_analyze/tests/specs/nursery/useFind/invalid.ts.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/nursery/useFind/valid.ts.snap is excluded by !**/*.snap and included by **
  • packages/@biomejs/backend-jsonrpc/src/workspace.ts is excluded by !**/backend-jsonrpc/src/workspace.ts and included by **
  • packages/@biomejs/biome/configuration_schema.json is excluded by !**/configuration_schema.json and included by **
📒 Files selected for processing (7)
  • .changeset/all-kiwis-poke.md (1 hunks)
  • crates/biome_js_analyze/src/lint/nursery/use_find.rs (1 hunks)
  • crates/biome_js_analyze/tests/specs/nursery/useFind/invalid.ts (1 hunks)
  • crates/biome_js_analyze/tests/specs/nursery/useFind/valid.ts (1 hunks)
  • crates/biome_js_type_info/src/type.rs (1 hunks)
  • crates/biome_rule_options/src/lib.rs (1 hunks)
  • crates/biome_rule_options/src/use_find.rs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
crates/biome_js_analyze/src/lint/nursery/use_find.rs (1)
crates/biome_analyze/src/rule.rs (4)
  • recommended (602-605)
  • sources (617-620)
  • same (246-251)
  • domains (632-635)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • GitHub Check: Validate rules documentation
  • GitHub Check: Documentation
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: autofix
  • GitHub Check: Check Dependencies
  • GitHub Check: Bench (biome_configuration)
  • GitHub Check: Test Node.js API
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: Check JS Files
  • GitHub Check: Bench (biome_js_formatter)
🔇 Additional comments (9)
crates/biome_rule_options/src/use_find.rs (1)

1-6: LGTM!

Empty options struct is appropriate for a rule with no configurable parameters. Standard derives and serde attributes are correctly applied.

.changeset/all-kiwis-poke.md (1)

1-13: LGTM!

Changeset documentation is clear and follows the standard format with helpful examples.

crates/biome_js_analyze/tests/specs/nursery/useFind/invalid.ts (1)

1-8: LGTM!

Test cases comprehensively cover the invalid patterns, including chaining scenarios and optional chaining.

crates/biome_rule_options/src/lib.rs (1)

295-295: LGTM!

Module export is correctly placed in alphabetical order.

crates/biome_js_analyze/tests/specs/nursery/useFind/valid.ts (1)

1-13: LGTM!

Valid test cases properly cover edge cases, including non-zero indices, method chaining, and object methods.

crates/biome_js_analyze/src/lint/nursery/use_find.rs (3)

1-46: LGTM!

Rule declaration and metadata are well-structured. Documentation includes clear examples, proper attribution to ESLint TypeScript's prefer-find, and appropriate configuration for a nursery rule.


48-51: LGTM!

Helper function correctly identifies first position using both number and bigint literal checks.


59-104: LGTM with a note on type safety.

The implementation correctly detects .filter()[0] and .filter().at(0) patterns. However, the rule relies on method name matching without verifying that filter is actually called on an Array type. This could theoretically flag custom objects with a filter method, though in practice this is likely acceptable for a nursery rule.

If stricter type checking is desired, consider verifying that the callee object is an array type using the type inference system.

crates/biome_js_type_info/src/type.rs (1)

203-216: The duplicate method definition claim is incorrect.

Verification shows only one is_bigint_literal definition at line 204. There is no duplication in the codebase. The original review comment was based on a false premise.

Likely an incorrect or invalid review comment.

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 14, 2025

CodSpeed Performance Report

Merging #8100 will not alter performance

Comparing Netail:feat/use-find (af1a98a) with main (1fdcaf0)

Summary

✅ 58 untouched
⏩ 95 skipped1

Footnotes

  1. 95 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Copy link
Contributor

@dyc3 dyc3 left a comment

Choose a reason for hiding this comment

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

Could we provide an unsafe code fix? No strong feelings on if you do it in this PR or a new one.

@Netail
Copy link
Member Author

Netail commented Nov 14, 2025

Could we provide an unsafe code fix? No strong feelings on if you do it in this PR or a new one.

Would do that in a new PR

@Netail Netail merged commit 82b9a8e into biomejs:main Nov 14, 2025
22 checks passed
@github-actions github-actions bot mentioned this pull request Nov 14, 2025
@Netail Netail deleted the feat/use-find branch November 14, 2025 18:36
ematipico pushed a commit to hamirmahal/biome that referenced this pull request Nov 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-CLI Area: CLI A-Diagnostic Area: diagnostocis A-Linter Area: linter A-Project Area: project A-Type-Inference Area: type inference L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

📎 Port prefer-find from typescript-eslint

2 participants