Skip to content

Commit 1ccdca3

Browse files
committed
docs(dev/guide): fix inaccurate single-letter rule references
Verified the guidance against `perfectionist` 0.0.0-rc.17 and corrected three claims that did not match the rules: - Remove the fabricated `short_impl_max_lines` knob from the generic naming section. The `single_letter_generic` rule has no configuration; canonical cases are silenced site-by-site with `#[allow]` or `#[expect]`. - Rename the `allowed_idents` knob to `extra_allowed_idents`, which is the actual field name for the variable and closure rules. - Clarify that `i`/`j`/`k` are exempt as function and closure parameters but not as `let` bindings, where only `n` is allowed. https://claude.ai/code/session_01CMrfXtuzxpSbchSJNuwboK
1 parent 4af0b48 commit 1ccdca3

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

CONTRIBUTING.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ Use **descriptive names** for type parameters, not single letters:
8989

9090
- `Size`, `Name`, `SizeGetter`, `HardlinksRecorder`, `Report`
9191

92-
Single-letter generics are acceptable only in very short, self-contained trait impls. Enforced by `perfectionist::single_letter_generic`; the threshold for "very short" is the rule's `short_impl_max_lines` knob in `dylint.toml`.
92+
Single-letter type parameters are flagged by `perfectionist::single_letter_generic`, which has no configuration. Genuinely canonical cases, such as `impl<T> From<T> for Wrapper<T>` where the trait already fixes the role of `T`, may be silenced site-by-site with `#[allow]` or `#[expect]`.
9393

9494
### Variable and Closure Parameter Naming
9595

96-
Use **descriptive names** for variables and closure parameters by default. Single-letter names are permitted only in the specific cases listed below. Enforced by `perfectionist::single_letter_let_binding`, `perfectionist::single_letter_function_param`, and `perfectionist::single_letter_closure_param`; the per-rule `allowed_idents` and `extra_trivial_callback_methods` knobs in `dylint.toml` reflect the exceptions documented here.
96+
Use **descriptive names** for variables and closure parameters by default. Single-letter names are permitted only in the specific cases listed below. Enforced by `perfectionist::single_letter_let_binding`, `perfectionist::single_letter_function_param`, and `perfectionist::single_letter_closure_param`. The exact exemptions differ by binding kind, as the cases below describe. The `extra_allowed_idents` and `extra_trivial_callback_methods` knobs in `dylint.toml` extend the built-in exempt sets, though the project currently relies on the defaults aside from the `sort_reflection_by` callback.
9797

9898
#### When single-letter names are allowed
9999

@@ -110,16 +110,16 @@ Use **descriptive names** for variables and closure parameters by default. Singl
110110
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { todo!() }
111111
```
112112

113-
- **Index variables (`i`, `j`, `k`):** These may only be used in two contexts: short closures, and index-based loops or iterations. The latter is rare in Rust. In all other cases, use `index`, `idx`, or `*_index`.
113+
- **Index variables (`i`, `j`, `k`):** These are exempt as function and closure parameters, and they read naturally in index-based loops or iterations, which are rare in Rust. They are not exempt as `let` bindings, where only `n` is allowed, so a `let` that holds an index must use `index`, `idx`, or `*_index` instead.
114114

115115
```rust
116-
// OK: short closure
116+
// OK: closure parameter
117117
left_indices.zip(right_indices).map(|(i, j)| matrix[i][j])
118118

119119
// OK: index-based loop
120120
for i in 0..len { /* ... */ }
121121

122-
// Bad: use a descriptive name instead
122+
// Bad: a `let` binding allows only `n`, never `i`
123123
let i = items.iter().position(|item| item.is_active()).unwrap();
124124
```
125125

0 commit comments

Comments
 (0)