From d00d03f0b45d2d1d6e0ae2d110c821b497d8fb09 Mon Sep 17 00:00:00 2001 From: piegames Date: Fri, 24 Mar 2023 16:39:42 +0100 Subject: [PATCH] Auto-format Rust code This should be checked in CI, really. --- src/alejandra/src/rules/inherit.rs | 12 +++++++----- src/alejandra/tests/fmt.rs | 9 +++++++-- src/alejandra_cli/src/cli.rs | 14 ++++++-------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/alejandra/src/rules/inherit.rs b/src/alejandra/src/rules/inherit.rs index 41716186..988c4256 100644 --- a/src/alejandra/src/rules/inherit.rs +++ b/src/alejandra/src/rules/inherit.rs @@ -53,8 +53,9 @@ pub(crate) fn rule( steps.push_back(crate::builder::Step::Whitespace); steps.push_back(crate::builder::Step::Comment(text)); steps.push_back(crate::builder::Step::NewLine); - // Only add padding if there are no `trivialities` (that is, there's no extra - // `Newlines(_)` to be added) or if the first one is a comment (that is, it'll need + // Only add padding if there are no `trivialities` (that is, + // there's no extra `Newlines(_)` to be added) + // or if the first one is a comment (that is, it'll need // to be indented to match the content). if matches!( child.trivialities.front(), @@ -77,9 +78,10 @@ pub(crate) fn rule( match trivia { crate::children2::Trivia::Comment(text) => { steps.push_back(crate::builder::Step::Comment(text)); - // If the next `trivia` is a newline, don't add newlines and padding at the - // end of this iteration, as it will lead to a new blank line in the - // output. + // If the next `trivia` is a newline, don't add newlines + // and padding at the + // end of this iteration, as it will lead to a new blank + // line in the output. if matches!( trivia_iter.peek(), Some(crate::children2::Trivia::Newlines(_)) diff --git a/src/alejandra/tests/fmt.rs b/src/alejandra/tests/fmt.rs index 92489746..f63cdec6 100644 --- a/src/alejandra/tests/fmt.rs +++ b/src/alejandra/tests/fmt.rs @@ -1,6 +1,7 @@ -use pretty_assertions::assert_eq; use std::io::Write; +use pretty_assertions::assert_eq; + #[test] fn cases() { let should_update = std::env::var("UPDATE").is_ok(); @@ -27,6 +28,10 @@ fn cases() { let content_out = std::fs::read_to_string(path_out.clone()).unwrap(); - assert_eq!(content_out, content_got, "Test case `{case}` failed; see `src/alejandra/tests/cases/{case}/`"); + assert_eq!( + content_out, content_got, + "Test case `{case}` failed; see \ + `src/alejandra/tests/cases/{case}/`" + ); } } diff --git a/src/alejandra_cli/src/cli.rs b/src/alejandra_cli/src/cli.rs index 24eac2bd..bab102c6 100644 --- a/src/alejandra_cli/src/cli.rs +++ b/src/alejandra_cli/src/cli.rs @@ -51,7 +51,7 @@ struct CLIArgs { #[derive(Clone)] struct FormattedPath { - pub path: String, + pub path: String, pub status: alejandra::format::Status, } @@ -147,12 +147,12 @@ pub fn main() -> std::io::Result<()> { let formatted_paths = match &include[..] { &[] | &["-"] => { vec![crate::cli::format_stdin(verbosity)] - }, + } include => { let paths = crate::find::nix_files(include, &args.exclude); crate::cli::format_paths(paths, in_place, verbosity, threads) - }, + } }; let errors = formatted_paths @@ -183,11 +183,9 @@ pub fn main() -> std::io::Result<()> { let changed = formatted_paths .iter() - .filter(|formatted_path| { - match formatted_path.status { - alejandra::format::Status::Changed(changed) => changed, - _ => false, - } + .filter(|formatted_path| match formatted_path.status { + alejandra::format::Status::Changed(changed) => changed, + _ => false, }) .count();