Skip to content

Commit

Permalink
Merge pull request #116 from mjago/heredoc_error
Browse files Browse the repository at this point in the history
Fix heredoc within parens formatting causing subsequent syntax error
  • Loading branch information
mjago authored Jul 27, 2018
2 parents dd14557 + 81f3517 commit c1ae045
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 c1ae045

Please sign in to comment.