Skip to content

Commit

Permalink
Fix for #45 for i, in ...
Browse files Browse the repository at this point in the history
  • Loading branch information
mjago committed Oct 29, 2017
1 parent ac66de3 commit 967d4be
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Fix formatting bug for `for i, in [[1, 2]] ; x ; end` issue #45

### Changed
The default for the following options has changed:
- parens_in_def: ~~dynamic~~ > yes
Expand Down
7 changes: 7 additions & 0 deletions lib/rufo/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1615,6 +1615,13 @@ def visit_for(node)
consume_space

visit_comma_separated_list to_ary(var)
skip_space
if comma?
check :on_comma
write ','
next_token
skip_space_or_newline
end

consume_space
consume_keyword "in"
Expand Down
17 changes: 14 additions & 3 deletions spec/lib/rufo/formatter_source_specs/for.rb.spec
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,26 @@ for x in y
2
end

#~# ORIGINAL
#~# PENDING
#~# ORIGINAL bug_45

for i, in [[1,2]]
i.should == 1
end

#~# EXPECTED

for i, in [[1,2]]
for i, in [[1, 2]]
i.should == 1
end

#~# ORIGINAL

for i,j, in [[1,2]]
i.should == 1
end

#~# EXPECTED

for i, j, in [[1, 2]]
i.should == 1
end

0 comments on commit 967d4be

Please sign in to comment.