Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]

### Fixed
- Fix crash when formatting an endless method with empty parentheses (`def foo() = 1`). ([#362](https://github.com/ruby-formatter/rufo/pull/362))

### Changed

Expand Down
3 changes: 3 additions & 0 deletions lib/rufo/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2015,6 +2015,9 @@ def visit_def_from_name(name, params, body)
check :on_rparen
next_token
write "()"
# Consume the space after `)` like the other branches do, so an endless
# method body (`def foo() = 1`) is detected below instead of crashing.
skip_space
else
write "("

Expand Down
12 changes: 12 additions & 0 deletions spec/lib/rufo/formatter_source_specs/endless_methods.rb.spec
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,15 @@ def foo = puts( "a")

#~# EXPECTED
def foo = puts("a")

#~# ORIGINAL format_endless_method_with_empty_params
def foo() = 1

#~# EXPECTED
def foo() = 1

#~# ORIGINAL format_endless_method_with_empty_params_and_spacing
def foo() = 1

#~# EXPECTED
def foo() = 1