diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 3d04055c..491030a1 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -24,4 +24,6 @@ jobs: steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 + with: + python-version: '3.x' - uses: pre-commit/action@v3.0.1 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 95c94c7a..24b1aa9f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -45,7 +45,7 @@ We ask that commits are atomic, meaning they are complete and have a single resp PRs should tell a cohesive story, with test and refactor commits that keep the fix or feature commits simple and clear. -Specifically, we would encouage +Specifically, we would encourage - File renames be isolated into their own commit - Add tests in a commit before their feature or fix, showing the current behavior. The diff for the feature/fix commit will then show how the behavior changed, diff --git a/Cargo.toml b/Cargo.toml index 61d9bfce..8fe444c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -83,6 +83,7 @@ string_lit_as_bytes = "warn" # string_to_string = "warn" todo = "warn" trait_duplication_in_bounds = "warn" +uninlined_format_args = "warn" verbose_file_reads = "warn" # wildcard_imports = "warn" zero_sized_map_values = "warn" diff --git a/crates/config/src/config.rs b/crates/config/src/config.rs index 3931a053..82034903 100644 --- a/crates/config/src/config.rs +++ b/crates/config/src/config.rs @@ -114,7 +114,7 @@ impl fmt::Display for Config { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut converted = serde_yaml::to_string(self).map_err(|_| fmt::Error)?; converted.drain(..4); - write!(f, "{}", converted) + write!(f, "{converted}") } } diff --git a/crates/config/src/document.rs b/crates/config/src/document.rs index cd5e3e44..22bf4006 100644 --- a/crates/config/src/document.rs +++ b/crates/config/src/document.rs @@ -187,7 +187,7 @@ mod test { fn split_document_no_new_line_after_front_matter() { let input = "invalid_front_matter---\nbody"; let (cobalt_model, content) = split_document(input); - println!("{:?}", cobalt_model); + println!("{cobalt_model:?}"); assert!(cobalt_model.is_none()); assert_eq!(content, input); } @@ -196,7 +196,7 @@ mod test { fn split_document_multiline_body() { let input = "---\ncobalt_model\n---\nfirst\nsecond"; let (cobalt_model, content) = split_document(input); - println!("{:?}", cobalt_model); + println!("{cobalt_model:?}"); assert_eq!(cobalt_model.unwrap(), "cobalt_model\n"); assert_eq!(content, "first\nsecond"); } diff --git a/crates/config/src/frontmatter.rs b/crates/config/src/frontmatter.rs index bd30d6b3..00a14424 100644 --- a/crates/config/src/frontmatter.rs +++ b/crates/config/src/frontmatter.rs @@ -145,7 +145,7 @@ impl fmt::Display for Frontmatter { if converted.is_empty() { Ok(()) } else { - write!(f, "{}", converted) + write!(f, "{converted}") } } } diff --git a/crates/config/src/path.rs b/crates/config/src/path.rs index aec319a9..3cc9f7aa 100644 --- a/crates/config/src/path.rs +++ b/crates/config/src/path.rs @@ -324,7 +324,7 @@ mod test_rel_path { #[test] fn test_try_from_abspath_fails() { let case = RelPath::try_from("/foo/bar"); - println!("{:?}", case); + println!("{case:?}"); assert!(case.is_err()); } } diff --git a/crates/engarde/src/raw.rs b/crates/engarde/src/raw.rs index 7f5e3d05..179379f7 100644 --- a/crates/engarde/src/raw.rs +++ b/crates/engarde/src/raw.rs @@ -27,12 +27,9 @@ impl Raw { pub fn format(&self, code: &str, lang: Option<&str>, _theme: Option<&str>) -> String { let code = html_escape(code); if let Some(ref lang) = lang { - format!( - "
{}
\n", - lang, code - ) + format!("
{code}
\n") } else { - format!("
{}
\n", code) + format!("
{code}
\n") } } } diff --git a/crates/file-serve/src/lib.rs b/crates/file-serve/src/lib.rs index f67486cd..d70cf302 100644 --- a/crates/file-serve/src/lib.rs +++ b/crates/file-serve/src/lib.rs @@ -70,7 +70,7 @@ impl ServerBuilder { Server { source, - addr: format!("{}:{}", hostname, port), + addr: format!("{hostname}:{port}"), server: RwLock::new(None), } } @@ -198,7 +198,7 @@ fn static_file_handler(dest: &std::path::Path, req: tiny_http::Request) -> Resul let file = std::fs::File::open(&serve_path).map_err(Error::new)?; let mut response = tiny_http::Response::from_file(file); if let Some(mime) = mime_guess::MimeGuess::from_path(&serve_path).first_raw() { - let content_type = format!("Content-Type:{}", mime); + let content_type = format!("Content-Type:{mime}"); let content_type = tiny_http::Header::from_str(&content_type).expect("formatted correctly"); response.add_header(content_type); diff --git a/crates/file-serve/src/main.rs b/crates/file-serve/src/main.rs index 5984dbc1..41e577c2 100644 --- a/crates/file-serve/src/main.rs +++ b/crates/file-serve/src/main.rs @@ -2,7 +2,7 @@ fn main() { let path = match std::env::current_dir() { Ok(path) => path, Err(err) => { - eprintln!("Cannot serve CWD: {}", err); + eprintln!("Cannot serve CWD: {err}"); std::process::exit(1); } }; diff --git a/src/bin/cobalt/debug.rs b/src/bin/cobalt/debug.rs index 323349ab..49bf2d23 100644 --- a/src/bin/cobalt/debug.rs +++ b/src/bin/cobalt/debug.rs @@ -42,20 +42,20 @@ impl DebugCommands { Self::Config { config } => { let config = config.load_config()?; let config = cobalt::cobalt_model::Config::from_config(config)?; - println!("{}", config); + println!("{config}"); } Self::Highlight(HighlightCommands::Themes { config }) => { let config = config.load_config()?; let config = cobalt::cobalt_model::Config::from_config(config)?; for name in config.syntax.themes() { - println!("{}", name); + println!("{name}"); } } Self::Highlight(HighlightCommands::Syntaxes { config }) => { let config = config.load_config()?; let config = cobalt::cobalt_model::Config::from_config(config)?; for name in config.syntax.syntaxes() { - println!("{}", name); + println!("{name}"); } } Self::Files { collection, config } => { diff --git a/src/bin/cobalt/new.rs b/src/bin/cobalt/new.rs index 9f59d8c7..f936eac6 100644 --- a/src/bin/cobalt/new.rs +++ b/src/bin/cobalt/new.rs @@ -243,7 +243,7 @@ pub(crate) fn create_new_document( (parent_dir, filename, ext) }; - let interim_path = parent_dir.join(format!("NON_EXISTENT.{}", extension)); + let interim_path = parent_dir.join(format!("NON_EXISTENT.{extension}")); let interim_path = cobalt_core::SourcePath::from_root(&config.source, &interim_path) .ok_or_else(|| { anyhow::format_err!( @@ -271,7 +271,7 @@ pub(crate) fn create_new_document( let source_path = config .source - .join(format!("_defaults/{}.{}", collection_slug, extension)); + .join(format!("_defaults/{collection_slug}.{extension}")); let source = if source_path.is_file() { cobalt_model::files::read_file(&source_path) .with_context(|| anyhow::format_err!("Failed to read default: {:?}", source_path))? diff --git a/src/bin/cobalt/serve.rs b/src/bin/cobalt/serve.rs index d24683b7..d309e312 100644 --- a/src/bin/cobalt/serve.rs +++ b/src/bin/cobalt/serve.rs @@ -97,7 +97,7 @@ fn serve(server: &file_serve::Server) -> Result<()> { fn open_browser(url: String) -> Result<()> { match open::that(url) { Ok(()) => info!("Please check your browser!"), - Err(why) => eprintln!("Failure to execute command: {}", why), + Err(why) => eprintln!("Failure to execute command: {why}"), } Ok(()) } diff --git a/src/cobalt_model/config.rs b/src/cobalt_model/config.rs index da408284..96be3d1b 100644 --- a/src/cobalt_model/config.rs +++ b/src/cobalt_model/config.rs @@ -80,15 +80,15 @@ impl Config { ignore.push(format!("/{}", rel_dest.to_owned()).into()); } } - ignore.push(format!("/{}", includes_dir).into()); - ignore.push(format!("/{}", layouts_dir).into()); + ignore.push(format!("/{includes_dir}").into()); + ignore.push(format!("/{layouts_dir}").into()); ignore.push("/_defaults".into()); ignore.push(format!("/{}", assets.sass.import_dir).into()); assert_eq!(pages.dir, ""); assert_eq!(pages.drafts_dir, None); ignore.push(format!("!/{}", posts.dir).into()); if let Some(dir) = posts.drafts_dir.as_deref() { - ignore.push(format!("!/{}", dir).into()); + ignore.push(format!("!/{dir}").into()); } ignore.extend(custom_ignore); @@ -151,7 +151,7 @@ impl fmt::Display for Config { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut converted = serde_yaml::to_string(self).map_err(|_| fmt::Error)?; converted.drain(..4); - write!(f, "{}", converted) + write!(f, "{converted}") } } diff --git a/src/cobalt_model/frontmatter.rs b/src/cobalt_model/frontmatter.rs index 2faadab9..43128349 100644 --- a/src/cobalt_model/frontmatter.rs +++ b/src/cobalt_model/frontmatter.rs @@ -110,7 +110,7 @@ impl fmt::Display for Frontmatter { if converted.is_empty() { Ok(()) } else { - write!(f, "{}", converted) + write!(f, "{converted}") } } } diff --git a/src/syntax_highlight.rs b/src/syntax_highlight.rs index 16ac37fd..a2cb2e62 100644 --- a/src/syntax_highlight.rs +++ b/src/syntax_highlight.rs @@ -241,8 +241,7 @@ mod test_syntsx { .unwrap(); let template = parser .parse(&format!( - "{{% highlight rust %}}{}{{% endhighlight %}}", - CODE_BLOCK + "{{% highlight rust %}}{CODE_BLOCK}{{% endhighlight %}}" )) .unwrap(); let output = template.render(&liquid::Object::new()); @@ -264,9 +263,8 @@ mod test_syntsx { fn markdown_renders_rust() { let html = format!( "```rust -{} -```", - CODE_BLOCK +{CODE_BLOCK} +```" ); let mut buf = String::new();