diff --git a/flake.nix b/flake.nix index b5fc500..b55522c 100644 --- a/flake.nix +++ b/flake.nix @@ -92,8 +92,8 @@ cargo-license cargo-tarpaulin jq - inputs.fenix.packages."x86_64-linux".stable.toolchain inputs.fenix.packages."x86_64-linux".latest.rustfmt + inputs.fenix.packages."x86_64-linux".stable.toolchain linuxPackages_latest.perf nodejs nodePackages.prettier diff --git a/rustfmt.toml b/rustfmt.toml index fa252a1..7d39985 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -21,5 +21,5 @@ struct_field_align_threshold = 999 unstable_features = true use_field_init_shorthand = true use_small_heuristics = "Max" -version = "Two" +style_edition = "2021" wrap_comments = true diff --git a/src/alejandra/src/builder.rs b/src/alejandra/src/builder.rs index f8fb830..712568b 100644 --- a/src/alejandra/src/builder.rs +++ b/src/alejandra/src/builder.rs @@ -34,7 +34,11 @@ pub(crate) fn build( build_step(&mut builder, build_ctx, &crate::builder::Step::Format(element)); if build_ctx.force_wide { - if build_ctx.force_wide_success { Some(builder.finish()) } else { None } + if build_ctx.force_wide_success { + Some(builder.finish()) + } else { + None + } } else { Some(builder.finish()) } diff --git a/src/alejandra/src/children.rs b/src/alejandra/src/children.rs index 2f9864e..be7772a 100644 --- a/src/alejandra/src/children.rs +++ b/src/alejandra/src/children.rs @@ -22,7 +22,11 @@ impl Children { matches!(child.kind(), rnix::SyntaxKind::TOKEN_COMMENT) }); - if has_comments { Some(build_ctx.pos_old.clone()) } else { None } + if has_comments { + Some(build_ctx.pos_old.clone()) + } else { + None + } }; for child in node.children_with_tokens() { diff --git a/src/alejandra_cli/tests/cli.rs b/src/alejandra_cli/tests/cli.rs index bab0a02..9de6513 100644 --- a/src/alejandra_cli/tests/cli.rs +++ b/src/alejandra_cli/tests/cli.rs @@ -13,24 +13,41 @@ struct TestCase { const CASES: &[TestCase] = &[ TestCase { args: &["--help"], stdin: None }, TestCase { args: &["--version"], stdin: None }, + // TestCase { args: &[], stdin: None }, + // changed + TestCase { args: &[], stdin: Some("[]") }, TestCase { args: &["--quiet"], stdin: Some("[]") }, TestCase { args: &["--quiet", "--quiet"], stdin: Some("[]") }, + // check unchanged + TestCase { args: &["--check"], stdin: Some("[]\n") }, TestCase { args: &["--check", "--quiet"], stdin: Some("[]\n") }, - TestCase { args: &["--check", "--quiet"], stdin: Some("[\t]") }, TestCase { args: &["--check", "--quiet", "--quiet"], stdin: Some("[]\n") }, + // check changed + TestCase { args: &["--check"], stdin: Some("[\t]") }, + TestCase { args: &["--check", "--quiet"], stdin: Some("[\t]") }, TestCase { args: &["--check", "--quiet", "--quiet"], stdin: Some("[\t]") }, + // check error + TestCase { args: &[], stdin: Some("[") }, TestCase { args: &["--quiet"], stdin: Some("[") }, TestCase { args: &["--quiet", "--quiet"], stdin: Some("[") }, + // nothing to format + TestCase { args: &[".", "--exclude", "."], stdin: None }, TestCase { args: &[".", "--exclude", ".", "--quiet"], stdin: None }, TestCase { args: &["--exclude", ".", "--quiet", "--quiet", "--", "."], stdin: None, }, + // + TestCase { args: &["--check", "tests/inputs/changed.nix"], stdin: None }, TestCase { args: &["--check", "tests/inputs/changed.nix", "--quiet"], stdin: None, }, + TestCase { + args: &["-c", "tests/inputs/changed.nix", "-e", "tests/changed.nix"], + stdin: None, + }, TestCase { args: &[ "-c", @@ -45,6 +62,7 @@ const CASES: &[TestCase] = &[ args: &["--check", "tests/inputs/changed.nix", "-qq"], stdin: None, }, + TestCase { args: &["-c", "tests/inputs/unchanged.nix"], stdin: None }, TestCase { args: &["--check", "tests/inputs/unchanged.nix", "-q"], stdin: None, @@ -53,6 +71,7 @@ const CASES: &[TestCase] = &[ args: &["--check", "tests/inputs/unchanged.nix", "-qq"], stdin: None, }, + TestCase { args: &["--check", "tests/inputs/error.nix"], stdin: None }, TestCase { args: &["--check", "tests/inputs/error.nix", "-q"], stdin: None, diff --git a/src/alejandra_cli/tests/output.txt b/src/alejandra_cli/tests/output.txt index 4ce495d..6b9e39e 100644 --- a/src/alejandra_cli/tests/output.txt +++ b/src/alejandra_cli/tests/output.txt @@ -62,6 +62,21 @@ stderr: exit code: Some(1) === +args: [] +stdin: "[]" +stdout: + [] + +stderr: + Formatting stdin. + Use --help to see all command line options. + use --quiet to suppress this and other messages. + + Success! 1 file was formatted. + + +exit code: Some(0) +=== args: ["--quiet"] stdin: "[]" stdout: @@ -74,6 +89,21 @@ stdin: "[]" stdout: [] +exit code: Some(0) +=== +args: ["--check"] +stdin: "[]\n" +stdout: + [] + +stderr: + Formatting stdin. + Use --help to see all command line options. + use --quiet to suppress this and other messages. + + Congratulations! Your code complies with the Alejandra style. + + exit code: Some(0) === args: ["--check", "--quiet"] @@ -83,6 +113,27 @@ stdout: exit code: Some(0) === +args: ["--check", "--quiet", "--quiet"] +stdin: "[]\n" +stdout: + [] + +exit code: Some(0) +=== +args: ["--check"] +stdin: "[\t]" +stdout: + [] + +stderr: + Formatting stdin. + Use --help to see all command line options. + use --quiet to suppress this and other messages. + + Alert! 1 file requires formatting. + +exit code: Some(2) +=== args: ["--check", "--quiet"] stdin: "[\t]" stdout: @@ -91,19 +142,27 @@ stdout: exit code: Some(2) === args: ["--check", "--quiet", "--quiet"] -stdin: "[]\n" -stdout: - [] - -exit code: Some(0) -=== -args: ["--check", "--quiet", "--quiet"] stdin: "[\t]" stdout: [] exit code: Some(2) === +args: [] +stdin: "[" +stdout: + [ + +stderr: + Formatting stdin. + Use --help to see all command line options. + use --quiet to suppress this and other messages. + + Failed! 1 error found at: + - : unexpected end of file + +exit code: Some(1) +=== args: ["--quiet"] stdin: "[" stdout: @@ -123,13 +182,47 @@ stdout: exit code: Some(1) === +args: [".", "--exclude", "."] +stderr: + Checking style in 0 files using 4 threads. + + + Congratulations! Your code complies with the Alejandra style. + + +exit code: Some(0) +=== args: [".", "--exclude", ".", "--quiet"] exit code: Some(0) === args: ["--exclude", ".", "--quiet", "--quiet", "--", "."] exit code: Some(0) === +args: ["--check", "tests/inputs/changed.nix"] +stdout: + Requires formatting: tests/inputs/changed.nix + +stderr: + Checking style in 1 file using 4 threads. + + + Alert! 1 file requires formatting. + +exit code: Some(2) +=== args: ["--check", "tests/inputs/changed.nix", "--quiet"] +exit code: Some(2) +=== +args: ["-c", "tests/inputs/changed.nix", "-e", "tests/changed.nix"] +stdout: + Requires formatting: tests/inputs/changed.nix + +stderr: + Checking style in 1 file using 4 threads. + + + Alert! 1 file requires formatting. + exit code: Some(2) === args: ["-c", "tests/inputs/changed.nix", "-q", "-e", "tests/changed.nix"] @@ -138,12 +231,32 @@ exit code: Some(2) args: ["--check", "tests/inputs/changed.nix", "-qq"] exit code: Some(2) === +args: ["-c", "tests/inputs/unchanged.nix"] +stderr: + Checking style in 1 file using 4 threads. + + + Congratulations! Your code complies with the Alejandra style. + + +exit code: Some(0) +=== args: ["--check", "tests/inputs/unchanged.nix", "-q"] exit code: Some(0) === args: ["--check", "tests/inputs/unchanged.nix", "-qq"] exit code: Some(0) === +args: ["--check", "tests/inputs/error.nix"] +stderr: + Checking style in 1 file using 4 threads. + + + Failed! 1 error found at: + - tests/inputs/error.nix: unexpected end of file + +exit code: Some(1) +=== args: ["--check", "tests/inputs/error.nix", "-q"] stderr: