Skip to content

Commit

Permalink
Auto-format Rust code
Browse files Browse the repository at this point in the history
This should be checked in CI, really.
  • Loading branch information
piegamesde authored and kamadorueda committed Mar 24, 2023
1 parent b9473ee commit d00d03f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
12 changes: 7 additions & 5 deletions src/alejandra/src/rules/inherit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(_))
Expand Down
9 changes: 7 additions & 2 deletions src/alejandra/tests/fmt.rs
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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}/`"
);
}
}
14 changes: 6 additions & 8 deletions src/alejandra_cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct CLIArgs {

#[derive(Clone)]
struct FormattedPath {
pub path: String,
pub path: String,
pub status: alejandra::format::Status,
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit d00d03f

Please sign in to comment.