Skip to content

Commit 5363de0

Browse files
committed
fix cargo fmt issue
1 parent a6fc3f0 commit 5363de0

File tree

5 files changed

+72
-79
lines changed

5 files changed

+72
-79
lines changed

src/app.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//! Defines the command-line interface for the lstr application.
22
3+
use crate::sort;
34
use clap::{Parser, Subcommand, ValueEnum};
45
use std::fmt;
56
use std::path::PathBuf;
6-
use crate::sort;
77

88
/// A blazingly fast, minimalist directory tree viewer, written in Rust.
99
#[derive(Parser, Debug)]

src/sort.rs

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub struct SortOptions {
5858
///
5959
/// ```rust
6060
/// use lstr::sort::{sort_entries, SortOptions, SortType};
61-
///
61+
///
6262
/// let mut entries = vec![/* ... */];
6363
/// let options = SortOptions {
6464
/// sort_type: SortType::Name,
@@ -84,7 +84,7 @@ fn compare_entries(a: &DirEntry, b: &DirEntry, options: &SortOptions) -> Orderin
8484
let b_is_dir = b.file_type().map(|ft| ft.is_dir()).unwrap_or(false);
8585
let a_is_dotfile = is_dotfile(a);
8686
let b_is_dotfile = is_dotfile(b);
87-
87+
8888
// Handle dotfiles-first and directories-first sorting
8989
// Order: dotfolders → folders → dotfiles → files
9090
if options.dotfiles_first {
@@ -94,7 +94,7 @@ fn compare_entries(a: &DirEntry, b: &DirEntry, options: &SortOptions) -> Orderin
9494
(false, true, false, true) | // Both regular folders
9595
(true, false, true, false) | // Both dotfiles
9696
(false, false, false, false) => {}, // Both regular files
97-
97+
9898
// Different categories - apply priority order
9999
(true, true, _, _) => return Ordering::Less, // a is dotfolder (highest priority)
100100
(_, _, true, true) => return Ordering::Greater, // b is dotfolder
@@ -111,7 +111,7 @@ fn compare_entries(a: &DirEntry, b: &DirEntry, options: &SortOptions) -> Orderin
111111
_ => {} // Both are dirs or both are files, continue
112112
}
113113
}
114-
114+
115115
// Apply the primary sorting strategy
116116
match options.sort_type {
117117
SortType::Name => compare_by_name(a, b, options),
@@ -125,7 +125,7 @@ fn compare_entries(a: &DirEntry, b: &DirEntry, options: &SortOptions) -> Orderin
125125
fn compare_by_name(a: &DirEntry, b: &DirEntry, options: &SortOptions) -> Ordering {
126126
let name_a = a.file_name();
127127
let name_b = b.file_name();
128-
128+
129129
if options.natural_sort {
130130
compare_natural(name_a, name_b)
131131
} else if options.case_sensitive {
@@ -147,10 +147,10 @@ fn compare_by_size(a: &DirEntry, b: &DirEntry) -> Ordering {
147147
fn compare_by_modified(a: &DirEntry, b: &DirEntry) -> Ordering {
148148
let modified_a = a.metadata().ok().and_then(|m| m.modified().ok());
149149
let modified_b = b.metadata().ok().and_then(|m| m.modified().ok());
150-
150+
151151
match (modified_a, modified_b) {
152152
(Some(a_time), Some(b_time)) => a_time.cmp(&b_time),
153-
(Some(_), None) => Ordering::Less, // Files with known time sort first
153+
(Some(_), None) => Ordering::Less, // Files with known time sort first
154154
(None, Some(_)) => Ordering::Greater,
155155
(None, None) => Ordering::Equal,
156156
}
@@ -160,13 +160,13 @@ fn compare_by_modified(a: &DirEntry, b: &DirEntry) -> Ordering {
160160
fn compare_by_extension(a: &DirEntry, b: &DirEntry, options: &SortOptions) -> Ordering {
161161
let ext_a = get_extension(a.file_name());
162162
let ext_b = get_extension(b.file_name());
163-
163+
164164
let ext_cmp = if options.case_sensitive {
165165
ext_a.cmp(&ext_b)
166166
} else {
167167
compare_case_insensitive_str(&ext_a, &ext_b)
168168
};
169-
169+
170170
// If extensions are equal, fall back to name comparison
171171
if ext_cmp == Ordering::Equal {
172172
compare_by_name(a, b, options)
@@ -180,7 +180,7 @@ fn compare_natural(a: &OsStr, b: &OsStr) -> Ordering {
180180
// Convert to strings for natural comparison
181181
let str_a = a.to_string_lossy();
182182
let str_b = b.to_string_lossy();
183-
183+
184184
// Use the natord crate for natural ordering
185185
natord::compare(&str_a, &str_b)
186186
}
@@ -196,12 +196,12 @@ fn compare_case_insensitive(a: &OsStr, b: &OsStr) -> Ordering {
196196
fn compare_default_order(a: &OsStr, b: &OsStr) -> Ordering {
197197
let str_a = a.to_string_lossy();
198198
let str_b = b.to_string_lossy();
199-
199+
200200
// Compare character by character using the specified priority
201201
for (char_a, char_b) in str_a.chars().zip(str_b.chars()) {
202202
let order_a = char_sort_priority(char_a);
203203
let order_b = char_sort_priority(char_b);
204-
204+
205205
match order_a.cmp(&order_b) {
206206
Ordering::Equal => {
207207
// Same priority category, compare within category
@@ -213,7 +213,7 @@ fn compare_default_order(a: &OsStr, b: &OsStr) -> Ordering {
213213
other => return other,
214214
}
215215
}
216-
216+
217217
// If all compared characters are equal, compare by length
218218
str_a.len().cmp(&str_b.len())
219219
}
@@ -233,10 +233,7 @@ fn char_sort_priority(c: char) -> u8 {
233233

234234
/// Checks if a directory entry is a dotfile/dotfolder (starts with '.').
235235
fn is_dotfile(entry: &DirEntry) -> bool {
236-
entry
237-
.file_name()
238-
.to_string_lossy()
239-
.starts_with('.')
236+
entry.file_name().to_string_lossy().starts_with('.')
240237
}
241238

242239
/// Performs case-insensitive comparison on regular strings.
@@ -271,7 +268,7 @@ mod tests {
271268
// Test case-insensitive comparison
272269
let name_a = OsStr::new("Apple");
273270
let name_b = OsStr::new("banana");
274-
271+
275272
let result = compare_case_insensitive(name_a, name_b);
276273
assert_eq!(result, Ordering::Less); // "apple" < "banana"
277274
}
@@ -280,7 +277,7 @@ mod tests {
280277
fn test_case_sensitive_name_sorting() {
281278
let name_a = OsStr::new("Apple");
282279
let name_b = OsStr::new("banana");
283-
280+
284281
let result = name_a.cmp(name_b);
285282
assert_eq!(result, Ordering::Less); // "Apple" < "banana" in ASCII
286283
}
@@ -289,22 +286,22 @@ mod tests {
289286
fn test_natural_sorting() {
290287
let name_a = OsStr::new("file1.txt");
291288
let name_b = OsStr::new("file10.txt");
292-
289+
293290
let result = compare_natural(name_a, name_b);
294291
assert_eq!(result, Ordering::Less); // file1 < file10 naturally
295-
292+
296293
// Test that regular lexicographic would give opposite result
297294
let lexicographic = name_a.cmp(name_b);
298295
assert_eq!(lexicographic, Ordering::Less); // Actually "file1.txt" < "file10.txt" lexicographically too
299-
296+
300297
// Better test: "file2.txt" vs "file10.txt"
301298
let name_c = OsStr::new("file2.txt");
302299
let name_d = OsStr::new("file10.txt");
303-
300+
304301
let natural_result = compare_natural(name_c, name_d);
305302
let lexicographic_result = name_c.cmp(name_d);
306-
307-
assert_eq!(natural_result, Ordering::Less); // file2 < file10 naturally
303+
304+
assert_eq!(natural_result, Ordering::Less); // file2 < file10 naturally
308305
assert_eq!(lexicographic_result, Ordering::Greater); // "file2.txt" > "file10.txt" lexicographically
309306
}
310307

@@ -328,14 +325,14 @@ mod tests {
328325
}
329326

330327
#[test]
331-
fn test_reverse_sorting() {
328+
fn test_reverse_sorting() {
332329
let name_a = OsStr::new("apple");
333330
let name_b = OsStr::new("banana");
334-
331+
335332
// Normal comparison: apple < banana
336333
let normal = compare_case_insensitive(name_a, name_b);
337334
assert_eq!(normal, Ordering::Less);
338-
335+
339336
// With reverse option, the final result should be flipped
340337
// (This would be handled by the sort_entries function)
341338
}
@@ -346,7 +343,7 @@ mod tests {
346343
assert_eq!(compare_default_order(OsStr::new("1file"), OsStr::new("Afile")), Ordering::Less);
347344
assert_eq!(compare_default_order(OsStr::new("Afile"), OsStr::new("afile")), Ordering::Less);
348345
assert_eq!(compare_default_order(OsStr::new("afile"), OsStr::new("zfile")), Ordering::Less);
349-
346+
350347
// Test within same category
351348
assert_eq!(compare_default_order(OsStr::new("1file"), OsStr::new("2file")), Ordering::Less);
352349
assert_eq!(compare_default_order(OsStr::new("Afile"), OsStr::new("Bfile")), Ordering::Less);
@@ -374,4 +371,4 @@ mod tests {
374371
assert!(!OsStr::new("visible.txt").to_string_lossy().starts_with('.'));
375372
assert!(!OsStr::new("normal").to_string_lossy().starts_with('.'));
376373
}
377-
}
374+
}

src/tui.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -342,18 +342,15 @@ fn scan_directory(
342342
) -> anyhow::Result<Vec<FileEntry>> {
343343
let mut builder = WalkBuilder::new(path);
344344
builder.hidden(!args.all).git_ignore(args.gitignore);
345-
345+
346346
// Collect all DirEntry objects first, filtering out the root path
347-
let mut dir_entries: Vec<_> = builder
348-
.build()
349-
.flatten()
350-
.filter(|result| result.path() != path)
351-
.collect();
352-
347+
let mut dir_entries: Vec<_> =
348+
builder.build().flatten().filter(|result| result.path() != path).collect();
349+
353350
// Apply sorting to the DirEntry objects
354351
let sort_options = args.to_sort_options();
355352
sort::sort_entries(&mut dir_entries, &sort_options);
356-
353+
357354
// Convert DirEntry objects to FileEntry objects
358355
let mut entries = Vec::new();
359356
for result in dir_entries {

src/view.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ pub fn run(args: &ViewArgs, ls_colors: &LsColors) -> anyhow::Result<()> {
7070
sort::sort_entries(&mut entries, &sort_options);
7171

7272
for entry in entries {
73-
7473
let is_dir = entry.file_type().is_some_and(|ft| ft.is_dir());
7574
if args.dirs_only && !is_dir {
7675
continue;

0 commit comments

Comments
 (0)