diff --git a/CHANGELOG.md b/CHANGELOG.md index 2231c68e..ce0fa02a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed +- Fix odd indentation of nested one liner "if" statements (issue [128](https://github.com/ruby-formatter/rufo/issues/128)) + ### Added - Ignore `vendor` directories from files to be checked. This allows rufo to be run without any arguments against a directory both locally and on common CI tools without needing any configuration. - Allow logging level to be configured with `--loglevel[=LEVEL]`. diff --git a/lib/rufo/formatter.rb b/lib/rufo/formatter.rb index 7b941cbb..ca1f0947 100644 --- a/lib/rufo/formatter.rb +++ b/lib/rufo/formatter.rb @@ -2819,7 +2819,7 @@ def visit_if_or_unless(node, keyword, check_end: true) if (else_body = node[3]) # [:else, else_contents] # [:elsif, cond, then, else] - write_indent + write_indent if @line != line case else_body[0] when :else diff --git a/spec/lib/rufo/formatter_source_specs/if.rb.spec b/spec/lib/rufo/formatter_source_specs/if.rb.spec index 23a0ce03..51dfce15 100644 --- a/spec/lib/rufo/formatter_source_specs/if.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/if.rb.spec @@ -182,3 +182,15 @@ end if 1 2 end + +#~# ORIGINAL + +if 1 +if 2 then 3 else 4 end +end + +#~# EXPECTED + +if 1 + if 2 then 3 else 4 end +end