Skip to content

Commit de2d681

Browse files
KSXGitHubclaude
andauthored
style: switch import granularity from "crate" to "module" (#435)
Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4849235 commit de2d681

69 files changed

Lines changed: 333 additions & 331 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/copilot-instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Read and follow the CONTRIBUTING.md file in this repository for all code style c
77
- Commit format: Conventional Commits. Pattern: `type(scope): lowercase description`. The scope is optional.
88
- Version releases are the only exception. The commit message is just the version number, such as `0.21.1`.
99
- Write documentation, comments, and other prose for ease of understanding first. Prefer a formal tone when it does not hurt clarity, and use complete sentences. Avoid mid-sentence breaks introduced by em dashes or long parenthetical clauses. Em dashes are a reliable symptom of loose phrasing; when one appears, restructure the surrounding sentence so each clause stands on its own rather than swapping the em dash for another punctuation mark.
10-
- Prefer merged imports.
10+
- Prefer imports merged per module. Combine items from the same module into a single `use` statement, but write a separate `use` statement for each module rather than collapsing every path from a crate into one nested-braces statement.
1111
- Use descriptive names for generics, such as `Size` and `Report`. Do not use single letters.
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)`.

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Read and follow the CONTRIBUTING.md file in this repository for all code style c
77
- Commit format: Conventional Commits. Pattern: `type(scope): lowercase description`. The scope is optional.
88
- Version releases are the only exception. The commit message is just the version number, such as `0.21.1`.
99
- Write documentation, comments, and other prose for ease of understanding first. Prefer a formal tone when it does not hurt clarity, and use complete sentences. Avoid mid-sentence breaks introduced by em dashes or long parenthetical clauses. Em dashes are a reliable symptom of loose phrasing; when one appears, restructure the surrounding sentence so each clause stands on its own rather than swapping the em dash for another punctuation mark.
10-
- Prefer merged imports.
10+
- Prefer imports merged per module. Combine items from the same module into a single `use` statement, but write a separate `use` statement for each module rather than collapsing every path from a crate into one nested-braces statement.
1111
- Use descriptive names for generics, such as `Size` and `Report`. Do not use single letters.
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)`.

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Read and follow the CONTRIBUTING.md file in this repository for all code style c
77
- Commit format: Conventional Commits. Pattern: `type(scope): lowercase description`. The scope is optional.
88
- Version releases are the only exception. The commit message is just the version number, such as `0.21.1`.
99
- Write documentation, comments, and other prose for ease of understanding first. Prefer a formal tone when it does not hurt clarity, and use complete sentences. Avoid mid-sentence breaks introduced by em dashes or long parenthetical clauses. Em dashes are a reliable symptom of loose phrasing; when one appears, restructure the surrounding sentence so each clause stands on its own rather than swapping the em dash for another punctuation mark.
10-
- Prefer merged imports.
10+
- Prefer imports merged per module. Combine items from the same module into a single `use` statement, but write a separate `use` statement for each module rather than collapsing every path from a crate into one nested-braces statement.
1111
- Use descriptive names for generics, such as `Size` and `Report`. Do not use single letters.
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)`.

CONTRIBUTING.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,16 @@ Automated tools enforce formatting (`cargo fmt`), linting (`cargo clippy`), and
3636

3737
### Import Organization
3838

39-
Prefer **merged imports**. Combine multiple items from the same crate or module into a single `use` statement with braces rather than separate `use` lines. Import ordering is enforced by `cargo fmt`. Imports gated by a platform attribute such as `#[cfg(unix)]` go in a separate block after the main imports.
39+
Prefer **merged imports** at module granularity. Combine multiple items from the same module into a single `use` statement with braces, but write a separate `use` statement for each module rather than collapsing every path from a crate into one nested-braces statement. This granularity is enforced by the `perfectionist::import_granularity` dylint check (`style = "module"`). Import ordering is enforced by `cargo fmt`. Imports gated by a platform attribute such as `#[cfg(unix)]` go in a separate block after the main imports.
4040

4141
```rust
42-
use crate::{
43-
args::{Args, Quantity, Threads},
44-
bytes_format::BytesFormat,
45-
size,
46-
};
42+
use crate::args::{Args, Quantity, Threads};
43+
use crate::bytes_format::BytesFormat;
44+
use crate::size;
4745
use clap::Parser;
4846
use pipe_trait::Pipe;
49-
use std::{io::stdin, time::Duration};
47+
use std::io::stdin;
48+
use std::time::Duration;
5049

5150
#[cfg(unix)]
5251
use crate::get_size::{GetBlockCount, GetBlockSize};

cli/ai_instructions.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
use clap::Parser;
22
use derive_more::Display;
33
use pipe_trait::Pipe;
4-
use std::{
5-
fmt,
6-
fs::{File, read_to_string},
7-
io::{self, Write},
8-
path::{Path, PathBuf},
9-
process::ExitCode,
10-
};
4+
use std::fmt;
5+
use std::fs::{File, read_to_string};
6+
use std::io::{self, Write};
7+
use std::path::{Path, PathBuf};
8+
use std::process::ExitCode;
119

1210
const SHARED: &str = include_str!("../template/ai-instructions/shared.md");
1311
const CLAUDE: &str = include_str!("../template/ai-instructions/claude.md");

dylint.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ prefix = [
1919
"LowerHex", "UpperHex", "Octal",
2020
]
2121

22-
# The intended long-term style is "module". It is set to "crate" for now.
23-
# See https://github.com/KSXGitHub/parallel-disk-usage/issues/432.
2422
["perfectionist::import_granularity"]
25-
style = "crate"
23+
style = "module"
2624

2725
["perfectionist::macro_argument_binding"]
2826
deny_extra = ["debug_assert_op", "debug_assert_op_expr"]

src/app.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@ pub mod sub;
22

33
pub use sub::Sub;
44

5-
use crate::{
6-
args::{Args, Quantity, Threads},
7-
bytes_format::BytesFormat,
8-
device::DeviceBoundary,
9-
get_size::{GetApparentSize, GetSize},
10-
hardlink,
11-
json_data::{JsonData, JsonDataBody, JsonShared, JsonTree},
12-
reporter::{ErrorOnlyReporter, ErrorReport, ProgressAndErrorReporter, ProgressReport},
13-
runtime_error::RuntimeError,
14-
size,
15-
visualizer::{BarAlignment, ColumnWidthDistribution, Direction, Visualizer},
16-
};
5+
use crate::args::{Args, Quantity, Threads};
6+
use crate::bytes_format::BytesFormat;
7+
use crate::device::DeviceBoundary;
8+
use crate::get_size::{GetApparentSize, GetSize};
9+
use crate::json_data::{JsonData, JsonDataBody, JsonShared, JsonTree};
10+
use crate::reporter::{ErrorOnlyReporter, ErrorReport, ProgressAndErrorReporter, ProgressReport};
11+
use crate::runtime_error::RuntimeError;
12+
use crate::visualizer::{BarAlignment, ColumnWidthDistribution, Direction, Visualizer};
13+
use crate::{hardlink, size};
1714
use clap::Parser;
1815
use hdd::any_path_is_in_hdd;
1916
use pipe_trait::Pipe;
20-
use std::{io::stdin, time::Duration};
17+
use std::io::stdin;
18+
use std::time::Duration;
2119
use sub::JsonOutputParam;
2220
use sysinfo::{Disk, Disks};
2321

src/app/hdd.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use super::mount_point::find_mount_point;
2-
use std::{
3-
ffi::OsStr,
4-
fs::canonicalize,
5-
io,
6-
path::{Path, PathBuf},
7-
};
2+
use std::ffi::OsStr;
3+
use std::fs::canonicalize;
4+
use std::io;
5+
use std::path::{Path, PathBuf};
86
use sysinfo::{Disk, DiskKind};
97

108
#[cfg(target_os = "linux")]

src/app/hdd/test.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
use super::{DiskApi, FsApi, any_path_is_in_hdd, path_is_in_hdd};
22
use pipe_trait::Pipe;
33
use pretty_assertions::assert_eq;
4-
use std::{
5-
ffi::OsStr,
6-
io,
7-
path::{Path, PathBuf},
8-
};
4+
use std::ffi::OsStr;
5+
use std::io;
6+
use std::path::{Path, PathBuf};
97
use sysinfo::DiskKind;
108

119
/// Fake disk for [`DiskApi`].

src/app/hdd/test_linux.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use super::{FsApi, VIRTUAL_DISK_KIND, parse_block_device_name, reclassify_virtual_hdd};
22
use pipe_trait::Pipe;
33
use pretty_assertions::assert_eq;
4-
use std::{
5-
io,
6-
path::{Path, PathBuf},
7-
};
4+
use std::io;
5+
use std::path::{Path, PathBuf};
86
use sysinfo::DiskKind;
97

108
/// Test pure parsing of block device names — no sysfs dependency.

0 commit comments

Comments
 (0)