rufo icon indicating copy to clipboard operation
rufo copied to clipboard

Error formatting endless method definitions

Open JosefuMealsom opened this issue 3 years ago • 4 comments

Seems to be an error with formatting endless method definitions in ruby as outlined here: https://rubyreferences.github.io/rubychanges/3.0.html#endless-method-definition

Example code:

class MyAwesomeClass
  def my_awesome_method = 123
end
/Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:2035:in `visit_def_from_name': undefined method `[]' for nil:NilClass (NoMethodError)
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:2005:in `block in visit_def'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:3707:in `push_hash'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:2004:in `visit_def'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:410:in `visit'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:526:in `block (2 levels) in visit_exps'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:3699:in `push_node'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:525:in `block in visit_exps'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:504:in `each'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:504:in `each_with_index'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:504:in `visit_exps'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:3467:in `block in indent_body'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:3391:in `indent'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:3466:in `indent_body'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:1578:in `visit_bodystmt'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:380:in `visit'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:1973:in `block in visit_class'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:3714:in `push_type'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:1957:in `visit_class'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:398:in `visit'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:526:in `block (2 levels) in visit_exps'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:3699:in `push_node'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:525:in `block in visit_exps'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:504:in `each'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:504:in `each_with_index'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:504:in `visit_exps'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:201:in `visit'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:177:in `format'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/command.rb:146:in `format'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/command.rb:107:in `format_file'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/command.rb:85:in `block in format_args'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/command.rb:78:in `each'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/command.rb:78:in `format_args'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/command.rb:40:in `run'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/lib/rufo/command.rb:12:in `run'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/gems/rufo-0.13.0/exe/rufo:4:in `<top (required)>'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/bin/rufo:23:in `load'
	from /Users/steve_mcrufo/.gem/ruby/3.0.2/bin/rufo:23:in `<top (required)>'
	from /Users/steve_mcrufo/.rubies/ruby-3.0.2/lib/ruby/3.0.0/bundler/cli/exec.rb:63:in `load'
	from /Users/steve_mcrufo/.rubies/ruby-3.0.2/lib/ruby/3.0.0/bundler/cli/exec.rb:63:in `kernel_load'
	from /Users/steve_mcrufo/.rubies/ruby-3.0.2/lib/ruby/3.0.0/bundler/cli/exec.rb:28:in `run'
	from /Users/steve_mcrufo/.rubies/ruby-3.0.2/lib/ruby/3.0.0/bundler/cli.rb:474:in `exec'
	from /Users/steve_mcrufo/.rubies/ruby-3.0.2/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
	from /Users/steve_mcrufo/.rubies/ruby-3.0.2/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
	from /Users/steve_mcrufo/.rubies/ruby-3.0.2/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
	from /Users/steve_mcrufo/.rubies/ruby-3.0.2/lib/ruby/3.0.0/bundler/cli.rb:30:in `dispatch'
	from /Users/steve_mcrufo/.rubies/ruby-3.0.2/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
	from /Users/steve_mcrufo/.rubies/ruby-3.0.2/lib/ruby/3.0.0/bundler/cli.rb:24:in `start'
	from /Users/steve_mcrufo/.rubies/ruby-3.0.2/lib/ruby/gems/3.0.0/gems/bundler-2.2.22/libexec/bundle:49:in `block in <top (required)>'
	from /Users/steve_mcrufo/.rubies/ruby-3.0.2/lib/ruby/3.0.0/bundler/friendly_errors.rb:128:in `with_friendly_errors'
	from /Users/steve_mcrufo/.rubies/ruby-3.0.2/lib/ruby/gems/3.0.0/gems/bundler-2.2.22/libexec/bundle:37:in `<top (required)>'
	from /Users/steve_mcrufo/.rubies/ruby-3.0.2/bin/bundle:23:in `load'
	from /Users/steve_mcrufo/.rubies/ruby-3.0.2/bin/bundle:23:in `<main>'

JosefuMealsom avatar Nov 08 '21 12:11 JosefuMealsom

PRs are welcome for this, I am not using Ruby for my daily work anymore so won't have time to fix it sorry

gingermusketeer avatar Nov 11 '21 20:11 gingermusketeer

@gingermusketeer thats cool. I've found the issue, but fitting that into the current code might take a little work. Would you be available to review the changes when I get around to it?

JosefuMealsom avatar Nov 15 '21 13:11 JosefuMealsom

@JosefuMealsom Yep I can take a look :)

gingermusketeer avatar Nov 15 '21 18:11 gingermusketeer

@JosefuMealsom @gingermusketeer Does this PR https://github.com/ruby-formatter/rufo/pull/274 close this issue?

manuraj17 avatar Sep 15 '22 10:09 manuraj17

Closed with #274 I have updated changelog, too https://github.com/ruby-formatter/rufo/commit/f1a869288a9b9ac98c81d042821a22e015c3504a

Thanks!

kzkn avatar Jan 22 '23 01:01 kzkn