mirror of
https://github.com/RGBCube/alejandra
synced 2025-07-31 12:37:45 +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::Whitespace);
|
||||||
steps.push_back(crate::builder::Step::Comment(text));
|
steps.push_back(crate::builder::Step::Comment(text));
|
||||||
steps.push_back(crate::builder::Step::NewLine);
|
steps.push_back(crate::builder::Step::NewLine);
|
||||||
// Only add padding if there are no `trivialities` (that is, there's no extra
|
// Only add padding if there are no `trivialities` (that is,
|
||||||
// `Newlines(_)` to be added) or if the first one is a comment (that is, it'll need
|
// 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).
|
// to be indented to match the content).
|
||||||
if matches!(
|
if matches!(
|
||||||
child.trivialities.front(),
|
child.trivialities.front(),
|
||||||
|
@ -77,9 +78,10 @@ pub(crate) fn rule(
|
||||||
match trivia {
|
match trivia {
|
||||||
crate::children2::Trivia::Comment(text) => {
|
crate::children2::Trivia::Comment(text) => {
|
||||||
steps.push_back(crate::builder::Step::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
|
// If the next `trivia` is a newline, don't add newlines
|
||||||
// end of this iteration, as it will lead to a new blank line in the
|
// and padding at the
|
||||||
// output.
|
// end of this iteration, as it will lead to a new blank
|
||||||
|
// line in the output.
|
||||||
if matches!(
|
if matches!(
|
||||||
trivia_iter.peek(),
|
trivia_iter.peek(),
|
||||||
Some(crate::children2::Trivia::Newlines(_))
|
Some(crate::children2::Trivia::Newlines(_))
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use pretty_assertions::assert_eq;
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
|
use pretty_assertions::assert_eq;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cases() {
|
fn cases() {
|
||||||
let should_update = std::env::var("UPDATE").is_ok();
|
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();
|
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)]
|
#[derive(Clone)]
|
||||||
struct FormattedPath {
|
struct FormattedPath {
|
||||||
pub path: String,
|
pub path: String,
|
||||||
pub status: alejandra::format::Status,
|
pub status: alejandra::format::Status,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,12 +147,12 @@ pub fn main() -> std::io::Result<()> {
|
||||||
let formatted_paths = match &include[..] {
|
let formatted_paths = match &include[..] {
|
||||||
&[] | &["-"] => {
|
&[] | &["-"] => {
|
||||||
vec![crate::cli::format_stdin(verbosity)]
|
vec![crate::cli::format_stdin(verbosity)]
|
||||||
},
|
}
|
||||||
include => {
|
include => {
|
||||||
let paths = crate::find::nix_files(include, &args.exclude);
|
let paths = crate::find::nix_files(include, &args.exclude);
|
||||||
|
|
||||||
crate::cli::format_paths(paths, in_place, verbosity, threads)
|
crate::cli::format_paths(paths, in_place, verbosity, threads)
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let errors = formatted_paths
|
let errors = formatted_paths
|
||||||
|
@ -183,11 +183,9 @@ pub fn main() -> std::io::Result<()> {
|
||||||
|
|
||||||
let changed = formatted_paths
|
let changed = formatted_paths
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|formatted_path| {
|
.filter(|formatted_path| match formatted_path.status {
|
||||||
match formatted_path.status {
|
alejandra::format::Status::Changed(changed) => changed,
|
||||||
alejandra::format::Status::Changed(changed) => changed,
|
_ => false,
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.count();
|
.count();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue