From f6aba3fe96c7162e31dbbdd166d8aabefce38162 Mon Sep 17 00:00:00 2001 From: Julian Frimmel Date: Fri, 20 Sep 2024 20:31:58 +0200 Subject: [PATCH 1/6] Inline some string formatting This fixes all occurences of `clippy::uninlined_format_args`. --- src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 38e0cfe05..e2913df40 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -96,8 +96,8 @@ impl<'a> Generator<'a> { } fn compile_sass(&self, filename: &str) -> eyre::Result<()> { - let scss_file = format!("./src/styles/{}.scss", filename); - let css_file = format!("./static/styles/{}.css", filename); + let scss_file = format!("./src/styles/{filename}.scss"); + let css_file = format!("./static/styles/{filename}.css"); let css = compile_file(&scss_file, Options::default()) .map_err(|error| eyre!(error)) @@ -113,7 +113,7 @@ impl<'a> Generator<'a> { fn concat_vendor_css(&self, files: Vec<&str>) -> eyre::Result<()> { let mut concatted = String::new(); for filestem in files { - let vendor_path = format!("./static/styles/{}.css", filestem); + let vendor_path = format!("./static/styles/{filestem}.css"); let contents = fs::read_to_string(vendor_path).wrap_err("couldn't read vendor css")?; concatted.push_str(&contents); } From 7e4e37e525bfd036c17ba9457a8c1b0167ce7a24 Mon Sep 17 00:00:00 2001 From: Julian Frimmel Date: Fri, 20 Sep 2024 20:34:15 +0200 Subject: [PATCH 2/6] Replace `Default::default()` with actual type This fixes the only occurence of `clippy::default_trait_access`. --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e2913df40..60377bbd4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,7 +5,7 @@ use self::blogs::Blog; use self::posts::Post; use chrono::Timelike; use eyre::{eyre, WrapErr}; -use handlebars::{handlebars_helper, Handlebars}; +use handlebars::{handlebars_helper, DirectorySourceOptions, Handlebars}; use rayon::prelude::*; use sass_rs::{compile_file, Options}; use serde_derive::Serialize; @@ -54,7 +54,7 @@ impl<'a> Generator<'a> { ) -> eyre::Result { let mut handlebars = Handlebars::new(); handlebars.set_strict_mode(true); - handlebars.register_templates_directory("templates", Default::default())?; + handlebars.register_templates_directory("templates", DirectorySourceOptions::default())?; handlebars.register_helper("month_name", Box::new(hb_month_name_helper)); Ok(Generator { From 377f1b6d2c32595f416d67233ec6d36a88862f82 Mon Sep 17 00:00:00 2001 From: Julian Frimmel Date: Fri, 20 Sep 2024 20:39:33 +0200 Subject: [PATCH 3/6] Use `let...else` --- src/posts.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/posts.rs b/src/posts.rs index bbfd6622d..01dd00e01 100644 --- a/src/posts.rs +++ b/src/posts.rs @@ -119,12 +119,11 @@ impl Post { lazy_static::lazy_static! { static ref R: Regex = Regex::new(r"(?P[^<]*) <(?P[^>]+)>").unwrap(); } - let captures = match R.captures(&s) { - Some(c) => c, - None => panic!( + let Some(captures) = R.captures(&s) else { + panic!( "team from path `{}` should have format `$name <$url>`", path.display() - ), + ) }; ( Some(captures["name"].to_string()), From d6dd018aacbfd6247fa2dc60f930fce95e4e8bcf Mon Sep 17 00:00:00 2001 From: Julian Frimmel Date: Fri, 20 Sep 2024 20:40:35 +0200 Subject: [PATCH 4/6] Remove some redundant `pub(crate)` modifiers This fixes all occurrences of `clippy::redundant_pub_crate`. --- src/blogs.rs | 6 +++--- src/posts.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/blogs.rs b/src/blogs.rs index 6d78946fb..87dcf0e63 100644 --- a/src/blogs.rs +++ b/src/blogs.rs @@ -7,7 +7,7 @@ static POSTS_EXT: &str = "md"; #[derive(Deserialize)] #[serde(rename_all = "kebab-case", deny_unknown_fields)] -pub(crate) struct Manifest { +pub struct Manifest { /// Title to display in the "top row". pub(crate) title: String, @@ -32,7 +32,7 @@ pub(crate) struct Manifest { } #[derive(Serialize)] -pub(crate) struct Blog { +pub struct Blog { title: String, index_title: String, link_text: String, @@ -121,7 +121,7 @@ impl Blog { /// Recursively load blogs in a directory. A blog is a directory with a `blog.yml` /// file inside it. -pub(crate) fn load(base: &Path) -> eyre::Result> { +pub fn load(base: &Path) -> eyre::Result> { let mut blogs = Vec::new(); load_recursive(base, base, &mut blogs)?; Ok(blogs) diff --git a/src/posts.rs b/src/posts.rs index 01dd00e01..197723fa6 100644 --- a/src/posts.rs +++ b/src/posts.rs @@ -15,7 +15,7 @@ struct YamlHeader { } #[derive(Debug, Clone, Serialize)] -pub(crate) struct Post { +pub struct Post { pub(crate) filename: String, pub(crate) layout: String, pub(crate) title: String, From 055b2b19307901f680b9be12df8afbf257742d26 Mon Sep 17 00:00:00 2001 From: Julian Frimmel Date: Fri, 20 Sep 2024 20:41:43 +0200 Subject: [PATCH 5/6] Use `Self` keyword where appropriate --- src/blogs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blogs.rs b/src/blogs.rs index 87dcf0e63..688759ebf 100644 --- a/src/blogs.rs +++ b/src/blogs.rs @@ -82,7 +82,7 @@ impl Blog { } } - Ok(Blog { + Ok(Self { title: manifest.title, index_title: manifest.index_title, description: manifest.description, From e8fb4045b9107fe6987021581724ad44cdc70830 Mon Sep 17 00:00:00 2001 From: Julian Frimmel Date: Fri, 20 Sep 2024 20:43:11 +0200 Subject: [PATCH 6/6] Replace manual expressions with `map_or[_else]()` This fixes the only occurrence of `clippy::option_if_let_else` and the only occurrence of `clippy::map_unwrap_or` --- src/blogs.rs | 3 +-- src/posts.rs | 32 ++++++++++++++------------------ 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/blogs.rs b/src/blogs.rs index 688759ebf..3e4b49f52 100644 --- a/src/blogs.rs +++ b/src/blogs.rs @@ -140,8 +140,7 @@ fn load_recursive(base: &Path, current: &Path, blogs: &mut Vec) -> eyre::R if file_name == MANIFEST_FILE { let prefix = parent .strip_prefix(base) - .map(|p| p.to_path_buf()) - .unwrap_or_else(|_| PathBuf::new()); + .map_or_else(|_| PathBuf::new(), Path::to_path_buf); blogs.push(Blog::load(prefix, parent)?); } } diff --git a/src/posts.rs b/src/posts.rs index 197723fa6..a1672e9db 100644 --- a/src/posts.rs +++ b/src/posts.rs @@ -114,25 +114,21 @@ impl Post { } // If they supplied team, it should look like `team-text ` - let (team, team_url) = match team_string { - Some(s) => { - lazy_static::lazy_static! { - static ref R: Regex = Regex::new(r"(?P[^<]*) <(?P[^>]+)>").unwrap(); - } - let Some(captures) = R.captures(&s) else { - panic!( - "team from path `{}` should have format `$name <$url>`", - path.display() - ) - }; - ( - Some(captures["name"].to_string()), - Some(captures["url"].to_string()), - ) + let (team, team_url) = team_string.map_or((None, None), |s| { + lazy_static::lazy_static! { + static ref R: Regex = Regex::new(r"(?P[^<]*) <(?P[^>]+)>").unwrap(); } - - None => (None, None), - }; + let Some(captures) = R.captures(&s) else { + panic!( + "team from path `{}` should have format `$name <$url>`", + path.display() + ) + }; + ( + Some(captures["name"].to_string()), + Some(captures["url"].to_string()), + ) + }); Ok(Self { filename,