diff --git a/src/rules/if_else.rs b/src/rules/if_else.rs index 79df182..1f56220 100644 --- a/src/rules/if_else.rs +++ b/src/rules/if_else.rs @@ -6,24 +6,11 @@ pub fn rule( let mut children = crate::children::Children::new(build_ctx, node); - let layout = if children.has_comments() { - &crate::config::Layout::Tall - } else { - build_ctx.config.layout() - }; - for branch in ["if", "then", "else"] { // if/then/else let child = children.get_next().unwrap(); steps.push_back(crate::builder::Step::Format(child.element)); - match layout { - crate::config::Layout::Tall => { - steps.push_back(crate::builder::Step::Indent); - } - crate::config::Layout::Wide => { - steps.push_back(crate::builder::Step::Whitespace); - } - } + steps.push_back(crate::builder::Step::Indent); // /**/ children.drain_comments(|text| { @@ -34,28 +21,15 @@ pub fn rule( // expr let child = children.get_next().unwrap(); - match layout { - crate::config::Layout::Tall => { - steps.push_back(crate::builder::Step::NewLine); - steps.push_back(crate::builder::Step::Pad); - steps.push_back(crate::builder::Step::FormatWider( - child.element, - )); - steps.push_back(crate::builder::Step::Dedent); - if branch != "else" { - steps.push_back(crate::builder::Step::NewLine); - steps.push_back(crate::builder::Step::Pad); - } - } - crate::config::Layout::Wide => { - steps.push_back(crate::builder::Step::Format(child.element)); - if branch != "else" { - steps.push_back(crate::builder::Step::Whitespace); - } - } - } + steps.push_back(crate::builder::Step::NewLine); + steps.push_back(crate::builder::Step::Pad); + steps.push_back(crate::builder::Step::FormatWider(child.element)); + steps.push_back(crate::builder::Step::Dedent); if branch != "else" { + steps.push_back(crate::builder::Step::NewLine); + steps.push_back(crate::builder::Step::Pad); + // /**/ children.drain_comments(|text| { steps.push_back(crate::builder::Step::Comment(text)); diff --git a/tests/cases/if_else/out b/tests/cases/if_else/out index 5af455d..ba2c44d 100644 --- a/tests/cases/if_else/out +++ b/tests/cases/if_else/out @@ -1,5 +1,12 @@ [ - (if a then b else c) + ( + if + a + then + b + else + c + ) ( if /**/ @@ -19,29 +26,92 @@ if ( if - (if a then b else c) + ( + if + a + then + b + else + c + ) then - (if a then b else c) + ( + if + a + then + b + else + c + ) else - (if a then b else c) + ( + if + a + then + b + else + c + ) ) then ( if - (if a then b else c) + ( + if + a + then + b + else + c + ) then - (if a then b else c) + ( + if + a + then + b + else + c + ) else - (if a then b else c) + ( + if + a + then + b + else + c + ) ) else ( if - (if a then b else c) + ( + if + a + then + b + else + c + ) then - (if a then b else c) + ( + if + a + then + b + else + c + ) else - (if a then b else c) + ( + if + a + then + b + else + c + ) ) ) then @@ -49,29 +119,92 @@ if ( if - (if a then b else c) + ( + if + a + then + b + else + c + ) then - (if a then b else c) + ( + if + a + then + b + else + c + ) else - (if a then b else c) + ( + if + a + then + b + else + c + ) ) then ( if - (if a then b else c) + ( + if + a + then + b + else + c + ) then - (if a then b else c) + ( + if + a + then + b + else + c + ) else - (if a then b else c) + ( + if + a + then + b + else + c + ) ) else ( if - (if a then b else c) + ( + if + a + then + b + else + c + ) then - (if a then b else c) + ( + if + a + then + b + else + c + ) else - (if a then b else c) + ( + if + a + then + b + else + c + ) ) ) else @@ -79,29 +212,92 @@ if ( if - (if a then b else c) + ( + if + a + then + b + else + c + ) then - (if a then b else c) + ( + if + a + then + b + else + c + ) else - (if a then b else c) + ( + if + a + then + b + else + c + ) ) then ( if - (if a then b else c) + ( + if + a + then + b + else + c + ) then - (if a then b else c) + ( + if + a + then + b + else + c + ) else - (if a then b else c) + ( + if + a + then + b + else + c + ) ) else ( if - (if a then b else c) + ( + if + a + then + b + else + c + ) then - (if a then b else c) + ( + if + a + then + b + else + c + ) else - (if a then b else c) + ( + if + a + then + b + else + c + ) ) ) )