seattlerb / ruby_parser

ruby_parser is a ruby parser written in pure ruby. It outputs s-expressions which can be manipulated and converted back to ruby via the ruby2ruby gem.
http://www.zenspider.com/projects/ruby_parser.html
476 stars 100 forks source link

Fix line numbering for method arguments without parentheses #297

Closed mvz closed 5 years ago

mvz commented 5 years ago

The line number for method arguments without parentheses is currently one more than it should be:

>> ENV['VERBOSE'] = 'true'
=> "true"
>> RubyParser.for_current_ruby.parse("def f(a)\nend")
=> s(:defn, :f, s(:args, :a).line(1), s(:nil).line(2)).line(1)
>> RubyParser.for_current_ruby.parse("def f a\nend")
=> s(:defn, :f, s(:args, :a).line(2), s(:nil).line(2)).line(1)

The line number for s(:args, :a) should be 1 in both cases.

This change fixes that problem.

zenspider commented 5 years ago

Fantastic. Thank you. Done!