-
-
Notifications
You must be signed in to change notification settings - Fork 713
docs: update documentation for useForOf
; fix typos
#7204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The description is based off the rule text from the original rule sources, using wording similar to other lint rules in the existing docs.
|
WalkthroughDocumentation-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
Suggested reviewers
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
useForOf
; fix typosuseForOf
; fix typos
useForOf
; fix typosuseForOf
; fix typos
There was a problem hiding this 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 nitsThe 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 exampleMake 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
📒 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 clearlyThis example matches the rule’s behaviour and clarifies the empty-initialiser case. LGTM.
CodSpeed Performance ReportMerging #7204 will not alter performanceComparing Summary
Footnotes |
Should i be concerned about the checks failing? |
There was a problem hiding this 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!
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 withfor [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