From: Ruben Beltran del Rio Date: Sat, 4 Jan 2025 00:44:35 +0000 (+0100) Subject: Some more linter improvements X-Git-Tag: 1.4.0~8 X-Git-Url: https://git.r.bdr.sh/rbdr/page/commitdiff_plain/b03284133baa6339fe4adf48e4a6499ef3ac287b Some more linter improvements --- diff --git a/src/file_finder.rs b/src/file_finder.rs index 754412a..a9b84f8 100644 --- a/src/file_finder.rs +++ b/src/file_finder.rs @@ -38,7 +38,7 @@ mod tests { use crate::file_handler::FileType; use test_utilities::*; - fn get_paths(root_directory: &PathBuf, files: &Vec) -> HashSet { + fn get_paths(root_directory: &PathBuf, files: &[File]) -> HashSet { files .iter() .map(|file| { @@ -54,8 +54,8 @@ mod tests { #[test] fn finds_all_files() { let test_dir = setup_test_dir(); - create_dir_all(&test_dir.join("nested")).expect("Could not create nested test directory"); - create_dir_all(&test_dir.join("assets")).expect("Could not create assets test directory"); + create_dir_all(test_dir.join("nested")).expect("Could not create nested test directory"); + create_dir_all(test_dir.join("assets")).expect("Could not create assets test directory"); create_test_file(&test_dir.join("test1.gmi"), ""); create_test_file(&test_dir.join("_layout.html"), ""); create_test_file(&test_dir.join("nested/nested.gmi"), ""); @@ -75,8 +75,8 @@ mod tests { #[test] fn identifies_correct_file_types() { let test_dir = setup_test_dir(); - create_dir_all(&test_dir.join("nested")).expect("Could not create nested test directory"); - create_dir_all(&test_dir.join("assets")).expect("Could not create assets test directory"); + create_dir_all(test_dir.join("nested")).expect("Could not create nested test directory"); + create_dir_all(test_dir.join("assets")).expect("Could not create assets test directory"); create_test_file(&test_dir.join("_layout.html"), ""); create_test_file(&test_dir.join("nested/nested.gmi"), ""); create_test_file(&test_dir.join("assets/style.css"), ""); @@ -102,9 +102,9 @@ mod tests { #[test] fn ignores_git_directory() { let test_dir = setup_test_dir(); - create_dir_all(&test_dir.join("nested")).expect("Could not create nested test directory"); - create_dir_all(&test_dir.join("assets")).expect("Could not create assets test directory"); - create_dir_all(&test_dir.join(".git")).expect("Could not create git test directory"); + create_dir_all(test_dir.join("nested")).expect("Could not create nested test directory"); + create_dir_all(test_dir.join("assets")).expect("Could not create assets test directory"); + create_dir_all(test_dir.join(".git")).expect("Could not create git test directory"); create_test_file(&test_dir.join("_layout.html"), ""); create_test_file(&test_dir.join("nested/nested.gmi"), ""); create_test_file(&test_dir.join("assets/style.css"), ""); diff --git a/src/file_handler/file_strategies/file.rs b/src/file_handler/file_strategies/file.rs index 601be87..c3c3016 100644 --- a/src/file_handler/file_strategies/file.rs +++ b/src/file_handler/file_strategies/file.rs @@ -104,7 +104,7 @@ mod tests { // Verify file contents are identical let original = fs::read(&file.path).unwrap(); - let copied = fs::read(&copied_path).unwrap(); + let copied = fs::read(copied_path).unwrap(); assert_eq!(original, copied); } @@ -115,7 +115,7 @@ mod tests { let output_dir = test_dir.join("output"); create_dir_all(&source_dir).expect("Could not create source test directory"); create_dir_all(&output_dir).expect("Could not create output test directory"); - create_dir_all(&source_dir.join("nested")).expect("Could not create source test directory"); + create_dir_all(source_dir.join("nested")).expect("Could not create source test directory"); create_test_file( &source_dir.join("nested/style.css"), "* { margin: 0; padding: 0 }", @@ -160,7 +160,7 @@ mod tests { // Verify file contents are identical let original = fs::read(&file.path).unwrap(); - let copied = fs::read(&copied_path).unwrap(); + let copied = fs::read(copied_path).unwrap(); assert_eq!(original, copied); } @@ -186,7 +186,7 @@ mod tests { // Verify file contents are identical let original = fs::read(&file.path).unwrap(); - let copied = fs::read(&copied_path).unwrap(); + let copied = fs::read(copied_path).unwrap(); assert_eq!(original, copied); } } diff --git a/src/file_handler/file_strategies/gemini.rs b/src/file_handler/file_strategies/gemini.rs index e987bab..32cb99e 100644 --- a/src/file_handler/file_strategies/gemini.rs +++ b/src/file_handler/file_strategies/gemini.rs @@ -238,7 +238,7 @@ Hello world file_type: FileType::Gemini, }; - strategy.handle_html(&source_dir, &output_dir, &file, &layout); + strategy.handle_html(&source_dir, &output_dir, &file, layout); let html_output = output_dir.join("test.html"); assert!(html_output.exists()); @@ -301,7 +301,7 @@ Hello world let test_dir = setup_test_dir(); let source_dir = test_dir.join("source"); let output_dir = test_dir.join("output"); - create_dir_all(&source_dir.join("nested")).expect("Could not create source test directory"); + create_dir_all(source_dir.join("nested")).expect("Could not create source test directory"); create_dir_all(&output_dir).expect("Could not create output test directory"); let layout = "\ @@ -328,7 +328,7 @@ Hello world file_type: FileType::Gemini, }; - strategy.handle_html(&source_dir, &output_dir, &file, &layout); + strategy.handle_html(&source_dir, &output_dir, &file, layout); let html_output = output_dir.join("nested/test.html"); assert!(html_output.exists()); diff --git a/src/file_handler/mod.rs b/src/file_handler/mod.rs index a079c74..522bcbf 100644 --- a/src/file_handler/mod.rs +++ b/src/file_handler/mod.rs @@ -156,7 +156,7 @@ mod tests { let files = vec![ create_test_internal_file("test.gmi", FileType::Gemini), create_test_internal_file( - &layout_path.to_str().expect("Could not encode layout"), + layout_path.to_str().expect("Could not encode layout"), FileType::Layout, ), create_test_internal_file("regular.html", FileType::File), @@ -231,18 +231,20 @@ mod tests { #[test] fn test_handle_with_layout() { - let mut handler = FileHandler::default(); - handler.layout = Some("test layout".to_string()); + let handler = FileHandler { + layout: Some("test layout".to_string()), + ..Default::default() + }; let test_dir = setup_test_dir(); - create_dir_all(&test_dir.join("output_html")) + create_dir_all(test_dir.join("output_html")) .expect("Could not create output html test directory"); - create_dir_all(&test_dir.join("output_gemini")) + create_dir_all(test_dir.join("output_gemini")) .expect("Could not create output gemini test directory"); let test_path = test_dir.join("test.gmi"); create_test_file(&test_path, ""); let file = create_test_internal_file( - &test_path + test_path .to_str() .expect("Could not encode gemini test file"), FileType::Gemini, @@ -279,33 +281,33 @@ mod tests { create_test_file(&test_dir.join("test1.gmi"), ""); create_test_file(&test_dir.join("test2.gmi"), ""); create_test_file(&test_dir.join("test3.gmi"), ""); - create_dir_all(&test_dir.join("output_html")) + create_dir_all(test_dir.join("output_html")) .expect("Could not create output html test directory"); - create_dir_all(&test_dir.join("output_gemini")) + create_dir_all(test_dir.join("output_gemini")) .expect("Could not create output gemini test directory"); let mut handler = FileHandler::default(); - let files = vec![ + let files = [ create_test_internal_file( - &test_dir + test_dir .join("test1.gmi") .to_str() .expect("Could not encode test1"), FileType::Gemini, ), create_test_internal_file( - &layout_path.to_str().expect("Could not encode layout"), + layout_path.to_str().expect("Could not encode layout"), FileType::Layout, ), create_test_internal_file( - &test_dir + test_dir .join("test2.gmi") .to_str() .expect("Could not encode test2"), FileType::Gemini, ), create_test_internal_file( - &test_dir + test_dir .join("test3.gmi") .to_str() .expect("Could not encode test3"),