Skip to content

Commit ddff668

Browse files
committed
Fix code formatting issues detected by rustfmt
1 parent edc2ffc commit ddff668

File tree

5 files changed

+100
-68
lines changed

5 files changed

+100
-68
lines changed

src/display/format.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn format_single_entry(
2222
entry: &DirectoryEntry,
2323
prefix: &str,
2424
is_last: bool,
25-
_config: &DisplayConfig, // Renamed to _config to avoid unused warning
25+
_config: &DisplayConfig, // Renamed to _config to avoid unused warning
2626
) -> String {
2727
let connector = if is_last { "└── " } else { "├── " };
2828

src/display/state.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,18 @@ impl<'a> DisplayState<'a> {
140140
self.depth
141141
);
142142

143-
let connector = if ctx.is_last { "└── " } else { "├── " };
143+
let connector = if ctx.is_last {
144+
"└── "
145+
} else {
146+
"├── "
147+
};
144148
let mut output = format!("{}{}{}", ctx.prefix, connector, entry.name);
145149

146150
if entry.is_gitignored && entry.is_dir {
147-
output.push_str(&format!(" {} [folded: system]\n", super::utils::format_metadata(entry)));
151+
output.push_str(&format!(
152+
" {} [folded: system]\n",
153+
super::utils::format_metadata(entry)
154+
));
148155
} else {
149156
output.push_str(&format!(" {}\n", super::utils::format_metadata(entry)));
150157
}
@@ -168,12 +175,17 @@ impl<'a> DisplayState<'a> {
168175
);
169176

170177
if items.is_empty() || self.lines_remaining == 0 {
171-
debug!("Early return: empty={}, no_lines={}", items.is_empty(), self.lines_remaining == 0);
178+
debug!(
179+
"Early return: empty={}, no_lines={}",
180+
items.is_empty(),
181+
self.lines_remaining == 0
182+
);
172183
return;
173184
}
174185

175186
let budget = self.calculate_level_budget(items.len());
176-
let section = self.calculate_display_section(items.len(), budget.min(self.config.dir_limit));
187+
let section =
188+
self.calculate_display_section(items.len(), budget.min(self.config.dir_limit));
177189

178190
debug!(
179191
"Display plan: budget={}, head={}, tail={}, hidden={}",
@@ -218,7 +230,10 @@ impl<'a> DisplayState<'a> {
218230

219231
// Show hidden items message if needed
220232
if section.total_hidden > 0 && self.lines_remaining > 0 {
221-
debug!("Adding hidden items indicator: {} items", section.total_hidden);
233+
debug!(
234+
"Adding hidden items indicator: {} items",
235+
section.total_hidden
236+
);
222237
self.output.push_str(&format!(
223238
"{}├── ... {} item{} hidden ...\n",
224239
prefix,

src/display/tests.rs

Lines changed: 64 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ fn test_head_tail_pattern() {
9595

9696
println!("Output:\n{}", state.output);
9797

98-
let visible_lines: Vec<_> = state.output
98+
let visible_lines: Vec<_> = state
99+
.output
99100
.lines()
100101
.filter(|l| !l.contains("items hidden"))
101102
.collect();
@@ -154,7 +155,8 @@ fn test_nested_directory_budget() {
154155
let dir_content = extract_directory_content(&state.output, dir);
155156
assert!(
156157
!dir_content.is_empty(),
157-
"Directory {} should show some content", dir
158+
"Directory {} should show some content",
159+
dir
158160
);
159161
}
160162
}
@@ -193,13 +195,18 @@ fn test_real_project_structure() {
193195
let mut state = DisplayState::new(config.max_lines, &config);
194196
state.show_items(&src_contents, "");
195197

196-
println!("\nTesting with max_lines = {}:\n{}", max_lines, state.output);
198+
println!(
199+
"\nTesting with max_lines = {}:\n{}",
200+
max_lines, state.output
201+
);
197202

198203
// Verify line limit
199204
let line_count = state.output.lines().count();
200205
assert!(
201206
line_count <= max_lines,
202-
"Output exceeded {} lines (got {})", max_lines, line_count
207+
"Output exceeded {} lines (got {})",
208+
max_lines,
209+
line_count
203210
);
204211

205212
// Verify content visibility
@@ -265,30 +272,42 @@ fn test_expanded_project_structure() {
265272

266273
// Test cases with expected content checks
267274
let test_cases = vec![
268-
(5, ExpectedContent {
269-
should_show_src: false,
270-
should_show_src_contents: false,
271-
min_visible_items: 2,
272-
should_show_head_tail: false,
273-
}),
274-
(10, ExpectedContent {
275-
should_show_src: true,
276-
should_show_src_contents: true,
277-
min_visible_items: 4,
278-
should_show_head_tail: true,
279-
}),
280-
(15, ExpectedContent {
281-
should_show_src: true,
282-
should_show_src_contents: true,
283-
min_visible_items: 6,
284-
should_show_head_tail: true,
285-
}),
286-
(20, ExpectedContent {
287-
should_show_src: true,
288-
should_show_src_contents: true,
289-
min_visible_items: 8,
290-
should_show_head_tail: true,
291-
}),
275+
(
276+
5,
277+
ExpectedContent {
278+
should_show_src: false,
279+
should_show_src_contents: false,
280+
min_visible_items: 2,
281+
should_show_head_tail: false,
282+
},
283+
),
284+
(
285+
10,
286+
ExpectedContent {
287+
should_show_src: true,
288+
should_show_src_contents: true,
289+
min_visible_items: 4,
290+
should_show_head_tail: true,
291+
},
292+
),
293+
(
294+
15,
295+
ExpectedContent {
296+
should_show_src: true,
297+
should_show_src_contents: true,
298+
min_visible_items: 6,
299+
should_show_head_tail: true,
300+
},
301+
),
302+
(
303+
20,
304+
ExpectedContent {
305+
should_show_src: true,
306+
should_show_src_contents: true,
307+
min_visible_items: 8,
308+
should_show_head_tail: true,
309+
},
310+
),
292311
];
293312

294313
for (max_lines, expected) in test_cases {
@@ -325,30 +344,38 @@ fn test_expanded_project_structure() {
325344
}
326345

327346
// Count visible items (non-hidden lines)
328-
let visible_items = output.lines()
347+
let visible_items = output
348+
.lines()
329349
.filter(|l| !l.contains("items hidden"))
330350
.count();
331351

332352
println!("Visible items: {}", visible_items);
333353

334354
// Basic structure checks based on available space
335355
if expected.should_show_src {
336-
assert!(output.contains("src"), "Should show src directory with {} lines", max_lines);
356+
assert!(
357+
output.contains("src"),
358+
"Should show src directory with {} lines",
359+
max_lines
360+
);
337361
}
338362

339363
if expected.should_show_src_contents {
340364
// For src directory
341365
assert!(
342366
output.contains("display") || output.contains("main.rs"),
343-
"Should show some src directory contents with {} lines", max_lines
367+
"Should show some src directory contents with {} lines",
368+
max_lines
344369
);
345370

346371
// Verify head/tail pattern if expected
347372
if expected.should_show_head_tail {
348373
let src_section = output
349374
.lines()
350375
.skip_while(|l| !l.contains("src"))
351-
.take_while(|l| l.starts_with("│ ") || l.starts_with("├──") || l.starts_with("└──"))
376+
.take_while(|l| {
377+
l.starts_with("│ ") || l.starts_with("├──") || l.starts_with("└──")
378+
})
352379
.collect::<Vec<_>>()
353380
.join("\n");
354381

@@ -408,29 +435,20 @@ fn test_extended_head_tail_pattern() {
408435
println!("Output:\n{}", state.output);
409436

410437
let output = state.output;
411-
438+
412439
println!("\nContent analysis:");
413440
for line in output.lines() {
414441
println!("{}", line);
415442
}
416443

417444
// Should show directory
418-
assert!(
419-
output.contains("src"),
420-
"Should show src directory"
421-
);
422-
445+
assert!(output.contains("src"), "Should show src directory");
446+
423447
// Should show some files from beginning
424-
assert!(
425-
output.contains("file1.rs"),
426-
"Should show first file"
427-
);
448+
assert!(output.contains("file1.rs"), "Should show first file");
428449

429450
// Should show hidden items indicator
430-
assert!(
431-
output.contains("items hidden"),
432-
"Should show hidden items"
433-
);
451+
assert!(output.contains("items hidden"), "Should show hidden items");
434452

435453
// Line limit verification
436454
assert!(

src/log_macros.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#[cfg(debug_assertions)]
32
#[macro_export]
43
macro_rules! debug_log {
@@ -39,4 +38,4 @@ macro_rules! info_log {
3938
#[macro_export]
4039
macro_rules! info_log {
4140
($($arg:tt)*) => {};
42-
}
41+
}

src/scanner.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub fn scan_directory(
1515
.file_name()
1616
.map(|n| n.to_string_lossy().to_string())
1717
.unwrap_or_else(|| root.to_string_lossy().to_string());
18-
18+
1919
// Early return for non-directories or when max_depth is 0
2020
if !root_metadata.is_dir() || max_depth == 0 {
2121
return Ok(DirectoryEntry {
@@ -32,7 +32,7 @@ pub fn scan_directory(
3232
is_gitignored: gitignore.is_ignored(root),
3333
});
3434
}
35-
35+
3636
// Initialize the root entry with temporary metadata
3737
// We'll calculate accurate size and file count as we traverse
3838
let mut root_entry = DirectoryEntry {
@@ -48,13 +48,13 @@ pub fn scan_directory(
4848
children: Vec::new(),
4949
is_gitignored: gitignore.is_ignored(root),
5050
};
51-
51+
5252
// For gitignored directories, provide basic metadata without deep traversal
5353
if root_entry.is_gitignored {
5454
// Do a quick scan to get file counts without going deep
5555
let mut file_count = 0;
5656
let mut total_size = 0;
57-
57+
5858
if let Ok(entries) = fs::read_dir(root) {
5959
for entry in entries.flatten() {
6060
if let Ok(metadata) = entry.metadata() {
@@ -69,29 +69,29 @@ pub fn scan_directory(
6969
}
7070
}
7171
}
72-
72+
7373
// If total size is still 0 but we know it's a directory, use a placeholder size
7474
if total_size == 0 && file_count > 0 {
7575
total_size = 1024 * 1024; // 1MB placeholder
7676
}
77-
77+
7878
// Update the metadata
7979
root_entry.metadata.files_count = file_count;
8080
root_entry.metadata.size = total_size;
81-
81+
8282
return Ok(root_entry);
8383
}
84-
84+
8585
let mut entries = Vec::new();
86-
86+
8787
// Read the directory and process entries
8888
for dir_entry in fs::read_dir(root)? {
8989
let dir_entry = dir_entry?;
9090
let path = dir_entry.path();
9191
let metadata = dir_entry.metadata()?;
9292
let name = dir_entry.file_name().to_string_lossy().to_string();
9393
let is_gitignored = gitignore.is_ignored(&path);
94-
94+
9595
if metadata.is_dir() {
9696
// Recursively scan subdirectories if depth allows
9797
if max_depth > 1 {
@@ -121,15 +121,15 @@ pub fn scan_directory(
121121
children: Vec::new(),
122122
is_gitignored,
123123
});
124-
124+
125125
// Update parent size
126126
root_entry.metadata.size += metadata.len();
127127
}
128128
} else {
129129
// For files, update parent metadata and add to entries
130130
root_entry.metadata.files_count += 1;
131131
root_entry.metadata.size += metadata.len();
132-
132+
133133
entries.push(DirectoryEntry {
134134
path,
135135
name,
@@ -145,9 +145,9 @@ pub fn scan_directory(
145145
});
146146
}
147147
}
148-
148+
149149
// Set the children
150150
root_entry.children = entries;
151-
151+
152152
Ok(root_entry)
153153
}

0 commit comments

Comments
 (0)