Skip to content

Commit 4a9e384

Browse files
authored
fix: prevent stripping parens in boolean expressions (#162) (#164)
1 parent d7b8692 commit 4a9e384

5 files changed

Lines changed: 12 additions & 0 deletions

File tree

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858

5959
# Not included in the package dependencies, but used for development
6060
rust-analyzer
61+
rustfmt
6162
];
6263
};
6364

src/formatting/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,10 @@ fn normalize_redundant_assignment_pipeline_parens(line: &str) -> String {
351351
return line.to_string();
352352
}
353353

354+
if rhs.contains(") and (") || rhs.contains(") or (") {
355+
return line.to_string();
356+
}
357+
354358
let lhs = line[..eq_idx].trim_end();
355359
format!("{lhs} = {inner}")
356360
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let has_update: bool = ($update_val != null) and ($update_val | is-not-empty)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let has_update: bool = ($update_val != null) and ($update_val | is-not-empty)

tests/ground_truth.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,4 +605,9 @@ fixture_tests!(
605605
ground_truth_closure_argument_pipe_spacing_normalized_issue160,
606606
idempotency_closure_argument_pipe_spacing_normalized_issue160
607607
),
608+
(
609+
"parens_stripping_boolean_exprs_issue162",
610+
ground_truth_parens_stripping_boolean_exprs_issue162,
611+
idempotency_parens_stripping_boolean_exprs_issue162
612+
),
608613
);

0 commit comments

Comments
 (0)