Skip to content

Commit

Permalink
Fix heredoc within parens formatting causing subsequent syntax error
Browse files Browse the repository at this point in the history
Fix for issue ruby-formatter#88
  • Loading branch information
mjago committed Jul 27, 2018
1 parent dd14557 commit 81f3517
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]

### Fixed
- Fix `quote_style` Bug: formatter.rb:3700:in `block in adjust_other_alignments': undefined method `[]' for nil:NilClass (NoMethodError) (issue [#87](https://github.com/ruby-formatter/rufo/issues/87)). Check alignment target exists.
- Fix `quote_style` Rufo keeps switching formatting on same file every time it runs (issue [#86](https://github.com/ruby-formatter/rufo/issues/86)). Avoids re-indenting nested literal indents.
- Fix Bug: Rufo breaks HEREDOC syntax. (issue [#88](https://github.com/ruby-formatter/rufo/issues/88)). This fixes heredoc within parens formatting causing bad formatting and subsequent syntax error.
- Fix Bug: formatter.rb:3700:in `block in adjust_other_alignments': undefined method `[]' for nil:NilClass (NoMethodError) (issue [#87](https://github.com/ruby-formatter/rufo/issues/87)). Check alignment target exists.
- Fix Bug: Rufo keeps switching formatting on same file every time it runs (issue [#86](https://github.com/ruby-formatter/rufo/issues/86)). Avoids re-indenting nested literal indents.

### Added
- Allow for simpler else_body node to suit new Ripper style in 2.6.0
Expand Down
2 changes: 2 additions & 0 deletions lib/rufo/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2080,11 +2080,13 @@ def visit_paren(node)
consume_token :on_lparen
skip_space_or_newline

heredoc = current_token_kind == :on_heredoc_beg
if exps
visit_exps to_ary(exps), with_lines: false
end

skip_space_or_newline
write "\n" if heredoc
consume_token :on_rparen
end

Expand Down
28 changes: 28 additions & 0 deletions spec/lib/rufo/formatter_source_specs/heredoc.rb.spec
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,31 @@ EOF
text
EOF
2 => 3}

#~# ORIGINAL heredoc_in_parens

(<<-E
abc
E
)

#~# EXPECTED

(<<-E
abc
E
)

#~# ORIGINAL heredoc_in_parens_following_space_and_command_issue_83

puts (<<-HELLO
hello world
HELLO
)

#~# EXPECTED

puts (<<-HELLO
hello world
HELLO
)

0 comments on commit 81f3517

Please sign in to comment.