fables-tales / rubyfmt

Ruby Autoformatter!
MIT License
1.07k stars 50 forks source link

Invalid code on chained method calls on variables/method with e.g. `group` name #418

Closed bquorning closed 1 year ago

bquorning commented 1 year ago

Input file

group(:foo).bar
group.(:foo).bar
group.foo(:bar).baz

Rubyfmt's output

group :foo.bar
group. :foo.bar
group.foo :bar.baz

This breaks because

I don’t think rubyfmt should have changed my source code. I understand (from #358) that the parentheses were removed because it looks better in Bundler’s gemfiles, but when I use group as a variable name, invalid code is produced. (The same problem happens if instead of group I use it, describe, gem, source, or ruby.)

A possible solution (with me having very little knowledge about rubyfmt’s internals) would be to check whether there are any method calls following the end-parenthesis before deciding whether it should be removed or not?

reese commented 1 year ago

Closing this as a duplicate of #414, which has the same root cause, and both of these issues should be resolved by #415