mirror of
https://github.com/RGBCube/alejandra
synced 2025-07-30 12:07:46 +00:00
Auto-format Rust code
This should be checked in CI, really.
This commit is contained in:
parent
b9473ee5ac
commit
d00d03f0b4
3 changed files with 20 additions and 15 deletions
|
@ -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(_))
|
||||
|
|
|
@ -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}/`"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue