diff --git a/flake.nix b/flake.nix index 047fba9..bcdc372 100644 --- a/flake.nix +++ b/flake.nix @@ -58,6 +58,7 @@ # Not included in the package dependencies, but used for development rust-analyzer + rustfmt ]; }; diff --git a/src/formatting/mod.rs b/src/formatting/mod.rs index 3300184..8701ada 100644 --- a/src/formatting/mod.rs +++ b/src/formatting/mod.rs @@ -351,6 +351,10 @@ fn normalize_redundant_assignment_pipeline_parens(line: &str) -> String { return line.to_string(); } + if rhs.contains(") and (") || rhs.contains(") or (") { + return line.to_string(); + } + let lhs = line[..eq_idx].trim_end(); format!("{lhs} = {inner}") } diff --git a/tests/fixtures/expected/parens_stripping_boolean_exprs_issue162.nu b/tests/fixtures/expected/parens_stripping_boolean_exprs_issue162.nu new file mode 100644 index 0000000..4177732 --- /dev/null +++ b/tests/fixtures/expected/parens_stripping_boolean_exprs_issue162.nu @@ -0,0 +1 @@ +let has_update: bool = ($update_val != null) and ($update_val | is-not-empty) diff --git a/tests/fixtures/input/parens_stripping_boolean_exprs_issue162.nu b/tests/fixtures/input/parens_stripping_boolean_exprs_issue162.nu new file mode 100644 index 0000000..0977ac9 --- /dev/null +++ b/tests/fixtures/input/parens_stripping_boolean_exprs_issue162.nu @@ -0,0 +1 @@ +let has_update: bool = ($update_val != null) and ($update_val | is-not-empty) diff --git a/tests/ground_truth.rs b/tests/ground_truth.rs index bef2992..3b4647a 100644 --- a/tests/ground_truth.rs +++ b/tests/ground_truth.rs @@ -605,4 +605,9 @@ fixture_tests!( ground_truth_closure_argument_pipe_spacing_normalized_issue160, idempotency_closure_argument_pipe_spacing_normalized_issue160 ), + ( + "parens_stripping_boolean_exprs_issue162", + ground_truth_parens_stripping_boolean_exprs_issue162, + idempotency_parens_stripping_boolean_exprs_issue162 + ), );