mirror of
https://github.com/casey/just.git
synced 2025-07-07 17:45:00 +00:00
Format if … else if …
without superfluous braces (#2573)
This commit is contained in:
parent
2a3018a529
commit
abec307f69
5 changed files with 30 additions and 7 deletions
|
@ -72,7 +72,13 @@ impl Display for Expression<'_> {
|
|||
condition,
|
||||
then,
|
||||
otherwise,
|
||||
} => write!(f, "if {condition} {{ {then} }} else {{ {otherwise} }}"),
|
||||
} => {
|
||||
if let Self::Conditional { .. } = **otherwise {
|
||||
write!(f, "if {condition} {{ {then} }} else {otherwise}")
|
||||
} else {
|
||||
write!(f, "if {condition} {{ {then} }} else {{ {otherwise} }}")
|
||||
}
|
||||
}
|
||||
Self::Group { contents } => write!(f, "({contents})"),
|
||||
Self::Join { lhs: None, rhs } => write!(f, "/ {rhs}"),
|
||||
Self::Join {
|
||||
|
|
|
@ -259,7 +259,7 @@ impl<'src> Lexer<'src> {
|
|||
|
||||
/// True if `text` could be an identifier
|
||||
pub(crate) fn is_identifier(text: &str) -> bool {
|
||||
if !text.chars().next().map_or(false, Self::is_identifier_start) {
|
||||
if !text.chars().next().is_some_and(Self::is_identifier_start) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -942,7 +942,7 @@ impl<'run, 'src> Parser<'run, 'src> {
|
|||
|
||||
let body = self.parse_body()?;
|
||||
|
||||
let shebang = body.first().map_or(false, Line::is_shebang);
|
||||
let shebang = body.first().is_some_and(Line::is_shebang);
|
||||
let script = attributes.contains(AttributeDiscriminant::Script);
|
||||
|
||||
if shebang && script {
|
||||
|
@ -1041,7 +1041,7 @@ impl<'run, 'src> Parser<'run, 'src> {
|
|||
}
|
||||
}
|
||||
|
||||
while lines.last().map_or(false, Line::is_empty) {
|
||||
while lines.last().is_some_and(Line::is_empty) {
|
||||
lines.pop();
|
||||
}
|
||||
|
||||
|
|
|
@ -204,11 +204,11 @@ impl<'src, D> Recipe<'src, D> {
|
|||
}
|
||||
let mut evaluated = String::new();
|
||||
let mut continued = false;
|
||||
let quiet_line = lines.peek().map_or(false, |line| line.is_quiet());
|
||||
let infallible_line = lines.peek().map_or(false, |line| line.is_infallible());
|
||||
let quiet_line = lines.peek().is_some_and(|line| line.is_quiet());
|
||||
let infallible_line = lines.peek().is_some_and(|line| line.is_infallible());
|
||||
|
||||
let comment_line = context.module.settings.ignore_comments
|
||||
&& lines.peek().map_or(false, |line| line.is_comment());
|
||||
&& lines.peek().is_some_and(|line| line.is_comment());
|
||||
|
||||
loop {
|
||||
if lines.peek().is_none() {
|
||||
|
|
|
@ -1138,3 +1138,20 @@ fn unchanged_justfiles_are_not_written_to_disk() {
|
|||
.args(["--fmt", "--unstable"])
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn if_else() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
x := if '' == '' { '' } else if '' == '' { '' } else { '' }
|
||||
",
|
||||
)
|
||||
.arg("--dump")
|
||||
.stdout(
|
||||
"
|
||||
x := if '' == '' { '' } else if '' == '' { '' } else { '' }
|
||||
",
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue