+
Skip to content

Conversation

Bertie690
Copy link
Contributor

@Bertie690 Bertie690 commented Aug 13, 2025

Rationale

There was a typo in the rules desc, as well as it being generally nondescript and lacking docs for examples.

See this issue on the documentation site for more context

Summary

The description was reworked with less typo and more clarity.
I based the content off the rule text from the original rule sources (typescript-eslint & unicorn), using wording similar to other lint rules in the existing docs.

(As an aside, we might want to look into adding an option to replace for loops which use indices & values solely in the loop body with for [i, v] of array.entries().

Test Plan

I'd presume I don't need to add tests for a documentation-only PR whose sole job is to edit a rust doc comment.
(I'd hope so at least)

Docs

I was told to make a PR to here instead of the docs site since it pulls the rule documentation from main.

Questions

Is a changeset required for a minor doc fix?
This is my first pr, so a little nervous

The description is based off the rule text from the original rule sources, using wording similar to other lint rules in the existing docs.
Copy link

changeset-bot bot commented Aug 13, 2025

⚠️ No Changeset found

Latest commit: 6e3f711

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Copy link
Contributor

coderabbitai bot commented Aug 13, 2025

Walkthrough

Documentation-only updates to the UseForOf lint rule in crates/biome_js_analyze/src/lint/style/use_for_of.rs. The description now generally advises preferring for-of loops, with an explicit exception when the index is declared outside the loop or used in the body (suggesting Array.entries() as an alternative). Examples were adjusted to illustrate both invalid and valid scenarios, including an empty-initialiser for loop using an externally declared index. No functional or public API changes.

Suggested labels

A-Linter, L-JavaScript

Suggested reviewers

  • siketyan
  • dyc3
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 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 13, 2025
@Bertie690 Bertie690 changed the title docs:Update documentation for useForOf; fix typos docs: Update documentation for useForOf; fix typos Aug 13, 2025
@Bertie690 Bertie690 changed the title docs: Update documentation for useForOf; fix typos docs: update documentation for useForOf; fix typos Aug 13, 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: 0

🧹 Nitpick comments (2)
crates/biome_js_analyze/src/lint/style/use_for_of.rs (2)

19-28: Tighten wording to match actual rule behaviour; minor phrasing nits

The implementation doesn’t distinguish reads vs writes to array elements; array[i] used as an lvalue still triggers the rule. The docs currently say “solely used to read”, which can mislead. Also, “within the outer scope” reads oddly, and “Array.entries()” should be “Array.prototype.entries()”. Trim incidental trailing spaces too.

Proposed wording tweaks:

-    /// This rule recommends using a `for...of` loop in place of a `for` loop 
-    /// when the loop index is solely used to read from the iterated array.
+    /// This rule recommends using a `for...of` loop instead of a `for` loop
+    /// when the loop index is only used to index into the same array referenced in the loop condition.
@@
-    /// ### Exceptions for Index Usage
-    /// When the loop index is declared within the outer scope or used anywhere within the loop body,
-    /// it is acceptable to use a `for` loop.
-    /// (`Array.entries()` can be used to a similar effect.)
+    /// ### Exceptions for index usage
+    /// When the loop index is declared outside the loop (in an outer scope) or used anywhere within the loop body,
+    /// it is acceptable to use a `for` loop.
+    /// (Alternatively, `Array.prototype.entries()` can be used to obtain both index and value.)

Optional: the diagnostic message elsewhere says “for-of” (hyphen) while the docs say “for...of”. Consider unifying the terminology in a follow-up.

Also, as this is Rustdoc in-source (per project guidelines), no changeset should be needed; please confirm with maintainers. And don’t forget to run just format before merging.


48-52: Clarify the inline comment in the valid example

Make it explicit why this for-loop is acceptable.

-    ///    // `i` is used, so for loop is OK
+    ///    // `i` is also used directly (not just for indexing), so a `for` loop is acceptable
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 232aaeb and 6e3f711.

📒 Files selected for processing (1)
  • crates/biome_js_analyze/src/lint/style/use_for_of.rs (3 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/style/use_for_of.rs
crates/biome_*/**/*

📄 CodeRabbit Inference Engine (CLAUDE.md)

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

Files:

  • crates/biome_js_analyze/src/lint/style/use_for_of.rs
🧠 Learnings (1)
📚 Learning: 2025-08-11T11:40:38.097Z
Learnt from: CR
PR: biomejs/biome#0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-08-11T11:40:38.097Z
Learning: For documentation of rules/assists/options, use inline Rustdoc in source code; other docs updates should go to the website repo’s next branch.

Applied to files:

  • crates/biome_js_analyze/src/lint/style/use_for_of.rs
🔇 Additional comments (1)
crates/biome_js_analyze/src/lint/style/use_for_of.rs (1)

60-66: Nice addition: covers the “index declared outside” exception clearly

This example matches the rule’s behaviour and clarifies the empty-initialiser case. LGTM.

Copy link

codspeed-hq bot commented Aug 13, 2025

CodSpeed Performance Report

Merging #7204 will not alter performance

Comparing Bertie690:fix-for-of-typo (6e3f711) with main (3b8fc9d)1

Summary

✅ 131 untouched benchmarks

Footnotes

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

@Bertie690
Copy link
Contributor Author

Should i be concerned about the checks failing?

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.

No changeset needed. LGTM, thank you!

@dyc3 dyc3 merged commit ece1643 into biomejs:main Aug 13, 2025
29 of 33 checks passed
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.

3 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载