Skip to content

Commit 156ff00

Browse files
author
ODAncona
committed
clippy auto fix
1 parent dc5f07f commit 156ff00

File tree

7 files changed

+81
-80
lines changed

7 files changed

+81
-80
lines changed

crates/code2prompt-core/tests/filter_test.rs

Lines changed: 58 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ use tempfile::{TempDir, tempdir};
1111
fn create_temp_file(dir: &Path, name: &str, content: &str) {
1212
let file_path = dir.join(name);
1313
let parent_dir = file_path.parent().unwrap();
14-
fs::create_dir_all(parent_dir).expect(&format!("Failed to create directory: {:?}", parent_dir));
14+
fs::create_dir_all(parent_dir).unwrap_or_else(|_| panic!("Failed to create directory: {:?}", parent_dir));
1515
let mut file =
16-
File::create(&file_path).expect(&format!("Failed to create temp file: {:?}", file_path));
17-
writeln!(file, "{}", content).expect(&format!("Failed to write to temp file: {:?}", file_path));
16+
File::create(&file_path).unwrap_or_else(|_| panic!("Failed to create temp file: {:?}", file_path));
17+
writeln!(file, "{}", content).unwrap_or_else(|_| panic!("Failed to write to temp file: {:?}", file_path));
1818
}
1919
static TEST_DIR: Lazy<TempDir> = Lazy::new(|| {
2020
let dir = tempdir().expect("Failed to create a temp directory");
@@ -61,20 +61,20 @@ mod tests {
6161
#[test]
6262
fn test_no_include_no_exclude_path() {
6363
let path = Path::new("src/main.rs");
64-
let include_patterns = build_globset(&vec![]);
65-
let exclude_patterns = build_globset(&vec![]);
64+
let include_patterns = build_globset(&[]);
65+
let exclude_patterns = build_globset(&[]);
6666
// ~~~ Must be included ~~~
6767
assert!(should_include_file(
68-
&path,
68+
path,
6969
&include_patterns,
7070
&exclude_patterns,
7171
));
7272
}
7373
#[test]
7474
fn test_no_include_no_exclude_empty() {
7575
let base_path = TEST_DIR.path();
76-
let include_patterns = build_globset(&vec![]);
77-
let exclude_patterns = build_globset(&vec![]);
76+
let include_patterns = build_globset(&[]);
77+
let exclude_patterns = build_globset(&[]);
7878
// ~~~ Must be included ~~~
7979
for file in [
8080
"lowercase/foo.py",
@@ -103,10 +103,10 @@ mod tests {
103103
#[test]
104104
fn test_no_include_exclude_path() {
105105
let path = Path::new("src/main.rs");
106-
let include_patterns = build_globset(&vec![]);
107-
let exclude_patterns = build_globset(&vec!["*.rs".to_string()]);
106+
let include_patterns = build_globset(&[]);
107+
let exclude_patterns = build_globset(&["*.rs".to_string()]);
108108
assert!(!should_include_file(
109-
&path,
109+
path,
110110
&include_patterns,
111111
&exclude_patterns,
112112
));
@@ -115,8 +115,8 @@ mod tests {
115115
/// Added for globset
116116
fn test_no_include_exclude_by_filename() {
117117
let base_path = TEST_DIR.path();
118-
let include_patterns = build_globset(&vec![]);
119-
let exclude_patterns = build_globset(&vec!["default_template.hbs".to_string()]);
118+
let include_patterns = build_globset(&[]);
119+
let exclude_patterns = build_globset(&["default_template.hbs".to_string()]);
120120
// ~~~ Must be excluded ~~~
121121
let excluded_path = base_path.join("src/default_template.hbs");
122122
assert!(!should_include_file(
@@ -128,8 +128,8 @@ mod tests {
128128
#[test]
129129
fn test_no_include_exclude_path_patterns() {
130130
let base_path = TEST_DIR.path();
131-
let include_patterns = build_globset(&vec![]);
132-
let exclude_patterns = build_globset(&vec!["lowercase/{*.txt,*.py}".to_string()]);
131+
let include_patterns = build_globset(&[]);
132+
let exclude_patterns = build_globset(&["lowercase/{*.txt,*.py}".to_string()]);
133133
// ~~~ Must be excluded ~~~
134134
for file in [
135135
"lowercase/qux.txt",
@@ -142,7 +142,7 @@ mod tests {
142142
let path = base_path.join(file);
143143
let relative_path = path.strip_prefix(base_path).unwrap();
144144
assert!(!should_include_file(
145-
&relative_path,
145+
relative_path,
146146
&include_patterns,
147147
&exclude_patterns,
148148
));
@@ -160,7 +160,7 @@ mod tests {
160160
let path = base_path.join(file);
161161
let relative_path = path.strip_prefix(base_path).unwrap();
162162
assert!(should_include_file(
163-
&relative_path,
163+
relative_path,
164164
&include_patterns,
165165
&exclude_patterns,
166166
));
@@ -169,8 +169,8 @@ mod tests {
169169
#[test]
170170
fn test_no_include_exclude_patterns() {
171171
let base_path = TEST_DIR.path();
172-
let include_patterns = build_globset(&vec![]);
173-
let exclude_patterns = build_globset(&vec!["*.txt".to_string()]);
172+
let include_patterns = build_globset(&[]);
173+
let exclude_patterns = build_globset(&["*.txt".to_string()]);
174174
// ~~~ Must be excluded ~~~
175175
for file in [
176176
"lowercase/qux.txt",
@@ -208,9 +208,9 @@ mod tests {
208208
#[test]
209209
fn test_no_include_exclude_files() {
210210
let base_path = TEST_DIR.path();
211-
let include_patterns = build_globset(&vec![]);
211+
let include_patterns = build_globset(&[]);
212212
let exclude_patterns =
213-
build_globset(&vec!["**/foo.py".to_string(), "**/bar.py".to_string()]);
213+
build_globset(&["**/foo.py".to_string(), "**/bar.py".to_string()]);
214214
// ~~~ Must be excluded ~~~
215215
for file in ["lowercase/foo.py", "lowercase/bar.py"] {
216216
let path = base_path.join(file);
@@ -245,8 +245,8 @@ mod tests {
245245
#[test]
246246
fn test_no_include_exclude_folders() {
247247
let base_path = TEST_DIR.path();
248-
let include_patterns = build_globset(&vec![]);
249-
let exclude_patterns = build_globset(&vec!["**/lowercase/**".to_string()]);
248+
let include_patterns = build_globset(&[]);
249+
let exclude_patterns = build_globset(&["**/lowercase/**".to_string()]);
250250
// ~~~ Must be excluded ~~~
251251
for file in ["lowercase/foo.py", "lowercase/bar.py", "lowercase/qux.txt"] {
252252
let path = base_path.join(file);
@@ -274,8 +274,8 @@ mod tests {
274274
#[test]
275275
fn test_include_no_exclude_patterns() {
276276
let base_path = TEST_DIR.path();
277-
let include_patterns = build_globset(&vec!["*.py".to_string()]);
278-
let exclude_patterns = build_globset(&vec![]);
277+
let include_patterns = build_globset(&["*.py".to_string()]);
278+
let exclude_patterns = build_globset(&[]);
279279
// ~~~ Must be included ~~~
280280
for file in [
281281
"lowercase/foo.py",
@@ -314,8 +314,8 @@ mod tests {
314314
/// added for globset
315315
fn test_include_no_exclude_by_filename() {
316316
let base_path = TEST_DIR.path();
317-
let include_patterns = build_globset(&vec!["default_template.hbs".to_string()]);
318-
let exclude_patterns = build_globset(&vec![]);
317+
let include_patterns = build_globset(&["default_template.hbs".to_string()]);
318+
let exclude_patterns = build_globset(&[]);
319319
// ~~~ Must be excluded ~~~
320320
for file in ["src/filter.rs", "src/git.rs", "src/lib.rs", "src/token.rs"] {
321321
let path = base_path.join(file);
@@ -337,8 +337,8 @@ mod tests {
337337
fn test_include_no_exclude_by_path_pattern() {
338338
let base_path = TEST_DIR.path();
339339
// let include_patterns = vec!["lowercase/*.txt".to_string(), "lowercase/*.py".to_string()];
340-
let include_patterns = build_globset(&vec!["lowercase/{*.txt,*.py}".to_string()]);
341-
let exclude_patterns = build_globset(&vec![]);
340+
let include_patterns = build_globset(&["lowercase/{*.txt,*.py}".to_string()]);
341+
let exclude_patterns = build_globset(&[]);
342342
// ~~~ Must be included ~~~
343343
for file in [
344344
"lowercase/qux.txt",
@@ -351,7 +351,7 @@ mod tests {
351351
let path = base_path.join(file);
352352
let relative_path = path.strip_prefix(base_path).unwrap();
353353
assert!(should_include_file(
354-
&relative_path,
354+
relative_path,
355355
&include_patterns,
356356
&exclude_patterns,
357357
));
@@ -369,7 +369,7 @@ mod tests {
369369
let path = base_path.join(file);
370370
let relative_path = path.strip_prefix(base_path).unwrap();
371371
assert!(!should_include_file(
372-
&relative_path,
372+
relative_path,
373373
&include_patterns,
374374
&exclude_patterns,
375375
));
@@ -378,8 +378,8 @@ mod tests {
378378
#[test]
379379
fn test_include_no_exclude_folders() {
380380
let base_path = TEST_DIR.path();
381-
let include_patterns = build_globset(&vec!["**/lowercase/**".to_string()]);
382-
let exclude_patterns = build_globset(&vec![]);
381+
let include_patterns = build_globset(&["**/lowercase/**".to_string()]);
382+
let exclude_patterns = build_globset(&[]);
383383
// ~~~ Must be included ~~~
384384
for file in ["lowercase/foo.py", "lowercase/bar.py", "lowercase/qux.txt"] {
385385
let path = base_path.join(file);
@@ -407,8 +407,8 @@ mod tests {
407407
fn test_include_no_exclude_files() {
408408
let base_path = TEST_DIR.path();
409409
let include_patterns =
410-
build_globset(&vec!["**/foo.py".to_string(), "**/bar.py".to_string()]);
411-
let exclude_patterns = build_globset(&vec![]);
410+
build_globset(&["**/foo.py".to_string(), "**/bar.py".to_string()]);
411+
let exclude_patterns = build_globset(&[]);
412412
// ~~~ Must be included ~~~
413413
for file in ["lowercase/foo.py", "lowercase/bar.py"] {
414414
let path = base_path.join(file);
@@ -444,10 +444,11 @@ mod tests {
444444
#[test]
445445
fn test_include_exclude_conflict_file() {
446446
let base_path = TEST_DIR.path();
447-
let include_patterns = build_globset(&vec!["**/foo.py".to_string()]);
448-
let exclude_patterns = build_globset(&vec!["**/foo.py".to_string()]);
447+
let include_patterns = build_globset(&["**/foo.py".to_string()]);
448+
let exclude_patterns = build_globset(&["**/foo.py".to_string()]);
449449
// ~~~ Must be excluded (exclude takes precedence) ~~~
450-
for file in ["lowercase/foo.py"] {
450+
{
451+
let file = "lowercase/foo.py";
451452
let path = base_path.join(file);
452453
assert!(!should_include_file(
453454
&path,
@@ -481,8 +482,8 @@ mod tests {
481482
#[test]
482483
fn test_include_exclude_conflict_extension() {
483484
let base_path = TEST_DIR.path();
484-
let include_patterns = build_globset(&vec!["*.py".to_string()]);
485-
let exclude_patterns = build_globset(&vec!["*.py".to_string()]);
485+
let include_patterns = build_globset(&["*.py".to_string()]);
486+
let exclude_patterns = build_globset(&["*.py".to_string()]);
486487
// ~~~ Must be excluded (exclude takes precedence) ~~~
487488
for file in [
488489
"lowercase/foo.py",
@@ -520,8 +521,8 @@ mod tests {
520521
#[test]
521522
fn test_include_exclude_conflict_folder() {
522523
let base_path = TEST_DIR.path();
523-
let include_patterns = build_globset(&vec!["**/lowercase/**".to_string()]);
524-
let exclude_patterns = build_globset(&vec!["**/lowercase/**".to_string()]);
524+
let include_patterns = build_globset(&["**/lowercase/**".to_string()]);
525+
let exclude_patterns = build_globset(&["**/lowercase/**".to_string()]);
525526
// ~~~ Must be excluded (exclude takes precedence) ~~~
526527
for file in [
527528
"lowercase/foo.py",
@@ -559,10 +560,11 @@ mod tests {
559560
#[test]
560561
fn test_include_exclude_exclude_takes_precedence() {
561562
let base_path = TEST_DIR.path();
562-
let include_patterns = build_globset(&vec!["**/*.py".to_string()]);
563-
let exclude_patterns = build_globset(&vec!["**/uppercase/*".to_string()]);
563+
let include_patterns = build_globset(&["**/*.py".to_string()]);
564+
let exclude_patterns = build_globset(&["**/uppercase/*".to_string()]);
564565
// ~~~ Must be included (not excluded) ~~~
565-
for file in ["lowercase/foo.py"] {
566+
{
567+
let file = "lowercase/foo.py";
566568
let path = base_path.join(file);
567569
assert!(should_include_file(
568570
&path,
@@ -571,7 +573,8 @@ mod tests {
571573
));
572574
}
573575
// ~~~ Must be excluded (exclude takes precedence) ~~~
574-
for file in ["uppercase/FOO.py"] {
576+
{
577+
let file = "uppercase/FOO.py";
575578
let path = base_path.join(file);
576579
assert!(!should_include_file(
577580
&path,
@@ -599,15 +602,15 @@ mod tests {
599602
let base_path = TEST_DIR.path();
600603
// This pattern uses brace expansion to match foo.py, bar.py, and baz.py
601604
// The issue was that the first item (foo.py) wasn't being considered
602-
let include_patterns = build_globset(&vec!["lowercase/{foo.py,bar.py,baz.py}".to_string()]);
605+
let include_patterns = build_globset(&["lowercase/{foo.py,bar.py,baz.py}".to_string()]);
603606
let exclude_patterns =
604-
build_globset(&vec!["lowercase/{qux.py,corge.py,grault.py}".to_string()]);
607+
build_globset(&["lowercase/{qux.py,corge.py,grault.py}".to_string()]);
605608
// ALL files in the brace expansion should be included
606609
for file in ["foo.py", "bar.py", "baz.py"] {
607610
let path = base_path.join("lowercase").join(file);
608611
let relative_path = path.strip_prefix(base_path).unwrap();
609612
assert!(
610-
should_include_file(&relative_path, &include_patterns, &exclude_patterns,),
613+
should_include_file(relative_path, &include_patterns, &exclude_patterns,),
611614
"Failed to include file: {}",
612615
file
613616
);
@@ -617,7 +620,7 @@ mod tests {
617620
let path = base_path.join("lowercase").join(file);
618621
let relative_path = path.strip_prefix(base_path).unwrap();
619622
assert!(
620-
!should_include_file(&relative_path, &include_patterns, &exclude_patterns,),
623+
!should_include_file(relative_path, &include_patterns, &exclude_patterns,),
621624
"Incorrectly included non-matching file: {}",
622625
file
623626
);
@@ -628,11 +631,9 @@ mod tests {
628631
fn test_brace_expansion_multiple_patterns() {
629632
let base_path = TEST_DIR.path();
630633
// Test with multiple patterns, each with brace expansion
631-
let include_patterns = build_globset(&vec![
632-
"lowercase/{foo,bar,baz}.py".to_string(),
633-
"uppercase/{FOO,BAR,BAZ}.py".to_string(),
634-
]);
635-
let exclude_patterns = build_globset(&vec![]);
634+
let include_patterns = build_globset(&["lowercase/{foo,bar,baz}.py".to_string(),
635+
"uppercase/{FOO,BAR,BAZ}.py".to_string()]);
636+
let exclude_patterns = build_globset(&[]);
636637
// All files in the brace expansions should be included
637638
for file in [
638639
"lowercase/foo.py",
@@ -645,7 +646,7 @@ mod tests {
645646
let path = base_path.join(file);
646647
let relative_path = path.strip_prefix(base_path).unwrap();
647648
assert!(
648-
should_include_file(&relative_path, &include_patterns, &exclude_patterns,),
649+
should_include_file(relative_path, &include_patterns, &exclude_patterns,),
649650
"Failed to include file: {}",
650651
file
651652
);
@@ -663,7 +664,7 @@ mod tests {
663664
let path = base_path.join(file);
664665
let relative_path = path.strip_prefix(base_path).unwrap();
665666
assert!(
666-
!should_include_file(&relative_path, &include_patterns, &exclude_patterns,),
667+
!should_include_file(relative_path, &include_patterns, &exclude_patterns,),
667668
"Incorrectly included non-matching file: {}",
668669
file
669670
);

crates/code2prompt-core/tests/git_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ mod tests {
310310
.expect("Failed to find first commit");
311311
repo.tag(
312312
"v1.0.0",
313-
&first_commit.as_object(),
313+
first_commit.as_object(),
314314
&signature,
315315
"Version 1.0.0",
316316
false,

crates/code2prompt-core/tests/path_test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ fn init_logger() {
2525
fn create_temp_file(dir: &Path, name: &str, content: &str) {
2626
let file_path = dir.join(name);
2727
let parent_dir = file_path.parent().unwrap();
28-
fs::create_dir_all(parent_dir).expect(&format!("Failed to create directory: {:?}", parent_dir));
28+
fs::create_dir_all(parent_dir).unwrap_or_else(|_| panic!("Failed to create directory: {:?}", parent_dir));
2929
let mut file =
30-
File::create(&file_path).expect(&format!("Failed to create temp file: {:?}", file_path));
30+
File::create(&file_path).unwrap_or_else(|_| panic!("Failed to create temp file: {:?}", file_path));
3131
//debug!("Writing to file: {:?}", file_path);
32-
writeln!(file, "{}", content).expect(&format!("Failed to write to temp file: {:?}", file_path));
32+
writeln!(file, "{}", content).unwrap_or_else(|_| panic!("Failed to write to temp file: {:?}", file_path));
3333
}
3434

3535
fn create_test_hierarchy(base_path: &Path) {

crates/code2prompt/tests/git_integration_test.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ fn init_logger() {
2626
fn create_temp_file(dir: &Path, name: &str, content: &str) {
2727
let file_path = dir.join(name);
2828
let parent_dir = file_path.parent().unwrap();
29-
fs::create_dir_all(parent_dir).expect(&format!("Failed to create directory: {:?}", parent_dir));
29+
fs::create_dir_all(parent_dir).unwrap_or_else(|_| panic!("Failed to create directory: {:?}", parent_dir));
3030
let mut file =
31-
File::create(&file_path).expect(&format!("Failed to create temp file: {:?}", file_path));
31+
File::create(&file_path).unwrap_or_else(|_| panic!("Failed to create temp file: {:?}", file_path));
3232
//debug!("Writing to file: {:?}", file_path);
33-
writeln!(file, "{}", content).expect(&format!("Failed to write to temp file: {:?}", file_path));
33+
writeln!(file, "{}", content).unwrap_or_else(|_| panic!("Failed to write to temp file: {:?}", file_path));
3434
}
3535

3636
fn create_test_hierarchy(base_path: &Path) {
@@ -67,7 +67,7 @@ fn create_test_hierarchy(base_path: &Path) {
6767

6868
fn read_output_file(dir: &Path, file_name: &str) -> String {
6969
let file_path = dir.join(file_name);
70-
read_to_string(&file_path).expect(&format!("Failed to read output file: {:?}", file_path))
70+
read_to_string(&file_path).unwrap_or_else(|_| panic!("Failed to read output file: {:?}", file_path))
7171
}
7272

7373
mod tests {
@@ -93,7 +93,7 @@ mod tests {
9393
fn command(&self) -> Command {
9494
let mut cmd =
9595
Command::cargo_bin("code2prompt").expect("Failed to find code2prompt binary");
96-
cmd.arg(&self.dir.path().to_str().unwrap())
96+
cmd.arg(self.dir.path().to_str().unwrap())
9797
.arg("--output-file")
9898
.arg(&self.output_file)
9999
.arg("--no-clipboard");

0 commit comments

Comments
 (0)