Skip to content

Commit 8c00d3e

Browse files
KSXGitHubclaude
andauthored
lint!: upgrade perfectionist (#412)
https://claude.ai/code/session_01CoRidYHvni9nKNgxMPXmfQ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 145bb5b commit 8c00d3e

28 files changed

Lines changed: 62 additions & 43 deletions

.github/copilot-instructions.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Read and follow the CONTRIBUTING.md file in this repository for all code style c
1212
- Use descriptive names for variables and closure parameters. Single letters are permitted only in these cases: (1) conventional names like `n` for count or `f` for formatter; (2) comparison closures like `|a, b|`; (3) trivial single-expression closures; (4) fold accumulators; (5) index variables `i`/`j`/`k` in short closures or index-based loops; and (6) test fixtures with identical roles. Single letters are never permitted in multi-line functions or closures.
1313
- Use `pipe-trait` to chain through unary functions such as constructors, `Some`, `Ok`, and free functions. Use it to flatten nested calls and to continue method chains. Do not use it for simple standalone calls; prefer `foo(value)` over `value.pipe(foo)`.
1414
- Prefer `where` clauses when a type has multiple trait bounds.
15-
- Derive order: standard traits, then comparison traits, then `Hash`, then `derive_more`, then feature-gated derives.
1615
- For error types, only derive `Display` and `Error` from `derive_more` when each is actually needed. Not all displayable types are errors.
1716
- Minimize `unwrap()` in non-test code. Use proper error handling instead.
1817
- Prefer `#[cfg_attr(..., ignore = "reason")]` over `#[cfg(...)]` when skipping tests. Use `#[cfg]` on tests only when the code cannot compile under the condition, such as when it references types or functions that do not exist on other platforms.

AGENTS.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Read and follow the CONTRIBUTING.md file in this repository for all code style c
1212
- Use descriptive names for variables and closure parameters. Single letters are permitted only in these cases: (1) conventional names like `n` for count or `f` for formatter; (2) comparison closures like `|a, b|`; (3) trivial single-expression closures; (4) fold accumulators; (5) index variables `i`/`j`/`k` in short closures or index-based loops; and (6) test fixtures with identical roles. Single letters are never permitted in multi-line functions or closures.
1313
- Use `pipe-trait` to chain through unary functions such as constructors, `Some`, `Ok`, and free functions. Use it to flatten nested calls and to continue method chains. Do not use it for simple standalone calls; prefer `foo(value)` over `value.pipe(foo)`.
1414
- Prefer `where` clauses when a type has multiple trait bounds.
15-
- Derive order: standard traits, then comparison traits, then `Hash`, then `derive_more`, then feature-gated derives.
1615
- For error types, only derive `Display` and `Error` from `derive_more` when each is actually needed. Not all displayable types are errors.
1716
- Minimize `unwrap()` in non-test code. Use proper error handling instead.
1817
- Prefer `#[cfg_attr(..., ignore = "reason")]` over `#[cfg(...)]` when skipping tests. Use `#[cfg]` on tests only when the code cannot compile under the condition, such as when it references types or functions that do not exist on other platforms.

CLAUDE.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Read and follow the CONTRIBUTING.md file in this repository for all code style c
1212
- Use descriptive names for variables and closure parameters. Single letters are permitted only in these cases: (1) conventional names like `n` for count or `f` for formatter; (2) comparison closures like `|a, b|`; (3) trivial single-expression closures; (4) fold accumulators; (5) index variables `i`/`j`/`k` in short closures or index-based loops; and (6) test fixtures with identical roles. Single letters are never permitted in multi-line functions or closures.
1313
- Use `pipe-trait` to chain through unary functions such as constructors, `Some`, `Ok`, and free functions. Use it to flatten nested calls and to continue method chains. Do not use it for simple standalone calls; prefer `foo(value)` over `value.pipe(foo)`.
1414
- Prefer `where` clauses when a type has multiple trait bounds.
15-
- Derive order: standard traits, then comparison traits, then `Hash`, then `derive_more`, then feature-gated derives.
1615
- For error types, only derive `Display` and `Error` from `derive_more` when each is actually needed. Not all displayable types are errors.
1716
- Minimize `unwrap()` in non-test code. Use proper error handling instead.
1817
- Prefer `#[cfg_attr(..., ignore = "reason")]` over `#[cfg(...)]` when skipping tests. Use `#[cfg]` on tests only when the code cannot compile under the condition, such as when it references types or functions that do not exist on other platforms.

CONTRIBUTING.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,12 @@ pub use event::Event;
7171

7272
### Derive Macro Ordering
7373

74-
When deriving multiple traits, use this order and split across multiple `#[derive(...)]` lines for readability:
74+
The order of trait names within each `#[derive(...)]` attribute is enforced automatically by the `perfectionist::derive_ordering` rule, configured for the `prefix_then_alphabetical` style. The configured `prefix` in `dylint.toml` lists the trait families in their project-preferred order: `Debug`, formatting / error derives (`Display`, `Error`), defaults (`Default`, `SmartDefault`), `Clone` / `Copy`, comparison and `Hash`, reference wrappers (`AsRef`, `AsMut`, `Deref`, `DerefMut`), conversions (`From`, `Into`, `TryFrom`, `TryInto`, `FromStr`), iteration, arithmetic operator pairs and folds, and integer-format derives. Any trait that is not in the `prefix` (project-specific derives such as `Setters` and `Parser`) falls in ASCII-case-insensitive alphabetical order after the prefix entries.
7575

76-
1. **Standard traits:** `Debug`, `Default`, `Clone`, `Copy`
77-
2. **Comparison traits:** `PartialEq`, `Eq`, `PartialOrd`, `Ord`
78-
3. **Hash**
79-
4. **`derive_more` traits:** `Display`, `From`, `Into`, `Add`, `AddAssign`, etc.
80-
5. **Feature-gated derives** on a separate `#[cfg_attr(...)]` line
76+
The remaining conventions are not enforced by the rule and must be applied by hand. When a type derives many traits, split them across multiple `#[derive(...)]` lines for readability, and place feature-gated derives on a separate `#[cfg_attr(...)]` line.
8177

8278
```rust
83-
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
79+
#[derive(Debug, Display, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
8480
#[derive(From, Into, Add, AddAssign, Sub, SubAssign, Sum)]
8581
#[cfg_attr(feature = "json", derive(Deserialize, Serialize))]
8682
pub struct Bytes(u64);
@@ -92,11 +88,11 @@ Use **descriptive names** for type parameters, not single letters:
9288

9389
- `Size`, `Name`, `SizeGetter`, `HardlinksRecorder`, `Report`
9490

95-
Single-letter generics are acceptable only in very short, self-contained trait impls.
91+
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`.
9692

9793
### Variable and Closure Parameter Naming
9894

99-
Use **descriptive names** for variables and closure parameters by default. Single-letter names are permitted only in the specific cases listed below.
95+
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.
10096

10197
#### When single-letter names are allowed
10298

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ terminal_size = "0.4.4"
8888
text-block-macros = "0.2.0"
8989
zero-copy-pads = "0.2.0"
9090

91+
[lints.rust]
92+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(dylint_lib, values("perfectionist"))'] }
93+
9194
[dev-dependencies]
9295
build-fs-tree = "0.8.1"
9396
command-extra = "1.0.0"

dylint.toml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,26 @@
11
[workspace.metadata.dylint]
22
libraries = [
3-
{ git = "https://github.com/KSXGitHub/perfectionist", tag = "0.0.0-rc.7" },
3+
{ git = "https://github.com/KSXGitHub/perfectionist", tag = "0.0.0-rc.14" },
44
]
5+
6+
["perfectionist::derive_ordering"]
7+
style = "prefix_then_alphabetical"
8+
prefix = [
9+
"Debug", "Display", "Error",
10+
"Default", "SmartDefault",
11+
"Clone", "Copy",
12+
"PartialEq", "Eq", "PartialOrd", "Ord",
13+
"Hash",
14+
"AsRef", "AsMut", "Deref", "DerefMut",
15+
"From", "Into", "TryFrom", "TryInto", "FromStr",
16+
"IntoIterator",
17+
"Add", "AddAssign", "Sub", "SubAssign", "Mul", "MulAssign", "Div", "DivAssign",
18+
"Sum", "Product",
19+
"LowerHex", "UpperHex", "Octal",
20+
]
21+
22+
["perfectionist::macro_argument_binding"]
23+
deny_extra = ["debug_assert_op", "debug_assert_op_expr"]
24+
25+
["perfectionist::single_letter_closure_param"]
26+
extra_trivial_callback_methods = ["sort_reflection_by"]

src/app/overlapping_arguments.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub trait Api {
1414
type RealPathError;
1515
fn canonicalize(path: &Self::Argument) -> Result<Self::RealPath, Self::RealPathError>;
1616
fn is_real_dir(path: &Self::Argument) -> bool;
17-
fn starts_with(a: &Self::RealPath, b: &Self::RealPath) -> bool;
17+
fn starts_with(path: &Self::RealPath, prefix: &Self::RealPath) -> bool;
1818
}
1919

2020
/// Implementation of [`Api`] that interacts with the real system.
@@ -36,8 +36,8 @@ impl Api for RealApi {
3636
}
3737

3838
#[inline]
39-
fn starts_with(a: &Self::RealPath, b: &Self::RealPath) -> bool {
40-
a.starts_with(b)
39+
fn starts_with(path: &Self::RealPath, prefix: &Self::RealPath) -> bool {
40+
path.starts_with(prefix)
4141
}
4242
}
4343

src/app/overlapping_arguments/test_remove_overlapping_paths.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ impl Api for MockedApi {
6464
.all(|(link, _)| PathBuf::from(link).normalize() != path)
6565
}
6666

67-
fn starts_with(a: &Self::RealPath, b: &Self::RealPath) -> bool {
68-
a.starts_with(b)
67+
fn starts_with(path: &Self::RealPath, prefix: &Self::RealPath) -> bool {
68+
path.starts_with(prefix)
6969
}
7070
}
7171

src/args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use terminal_size::{Width, terminal_size};
1717
use text_block_macros::text_block;
1818

1919
/// The CLI arguments.
20-
#[derive(Debug, SmartDefault, Setters, Clone, Parser)]
20+
#[derive(Debug, SmartDefault, Clone, Parser, Setters)]
2121
#[clap(
2222
name = "pdu",
2323

src/args/depth.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{
77
const INFINITE: &str = "inf";
88

99
/// Maximum depth of the tree.
10-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Display)]
10+
#[derive(Debug, Display, Clone, Copy, PartialEq, Eq)]
1111
pub enum Depth {
1212
#[display("{INFINITE}")]
1313
Infinite,
@@ -25,7 +25,7 @@ impl Depth {
2525
}
2626

2727
/// Error that occurs when parsing a string as [`Depth`].
28-
#[derive(Debug, Display, Clone, PartialEq, Eq, Error)]
28+
#[derive(Debug, Display, Error, Clone, PartialEq, Eq)]
2929
#[non_exhaustive]
3030
pub enum FromStrError {
3131
#[display("Value is neither {INFINITE:?} nor a positive integer: {_0}")]

0 commit comments

Comments
 (0)