ruby-formatter / rufo

The Ruby Formatter
MIT License
894 stars 56 forks source link

Exception when omitting hash value at method call #298

Closed sk8higher closed 1 year ago

sk8higher commented 1 year ago

I have a bug when I try to save code with this method:

def digest(string)
    cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST : BCrypt::Engine.cost
    BCrypt::Password.create(string, cost:)
  end

It was corrected by Rubocop

C: [Correctable] Style/HashSyntax: Omit the hash value.
    BCrypt::Password.create(string, cost: cost)

Full trace:


You've found a bug!
Please report it to https://github.com/ruby-formatter/rufo/issues with code that triggers it
/home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:3582:in `bug': unexpected node:  at [[39, 41], :on_rparen, ")", ENDFN] at [[39, 41], :on_rparen, ")", ENDFN] (Rufo::Bug)
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:193:in `visit'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:2383:in `visit_hash_key_value'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:422:in `visit'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:1790:in `block (2 levels) in visit_comma_separated_list'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:3479:in `maybe_indent'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:1786:in `block in visit_comma_separated_list'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:1785:in `each'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:1785:in `each_with_index'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:1785:in `visit_comma_separated_list'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:363:in `block in visit'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:3387:in `indent'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:362:in `visit'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:1790:in `block (2 levels) in visit_comma_separated_list'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:3479:in `maybe_indent'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:1786:in `block in visit_comma_separated_list'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:1785:in `each'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:1785:in `each_with_index'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:1785:in `visit_comma_separated_list'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:1508:in `visit_call_args'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:355:in `visit'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:1123:in `block in visit_call_at_paren'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:3690:in `block (2 levels) in push_call'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:3707:in `push_hash'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:3689:in `block in push_call'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:3699:in `push_node'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:3686:in `push_call'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:1122:in `visit_call_at_paren'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:1083:in `block in visit_call_without_receiver'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:3479:in `maybe_indent'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:1082:in `visit_call_without_receiver'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:366:in `visit'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:526:in `block (2 levels) in visit_exps'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:3699:in `push_node'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:525:in `block in visit_exps'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:504:in `each'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:504:in `each_with_index'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:504:in `visit_exps'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:3467:in `block in indent_body'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:3391:in `indent'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:3466:in `indent_body'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:1578:in `visit_bodystmt'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:380:in `visit'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:2088:in `visit_def_from_name'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:2005:in `block in visit_def'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:3707:in `push_hash'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:2004:in `visit_def'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:410:in `visit'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:526:in `block (2 levels) in visit_exps'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:3699:in `push_node'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:525:in `block in visit_exps'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:504:in `each'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:504:in `each_with_index'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:504:in `visit_exps'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:3467:in `block in indent_body'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:3391:in `indent'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:3466:in `indent_body'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:1578:in `visit_bodystmt'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:380:in `visit'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:1973:in `block in visit_class'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:3714:in `push_type'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:1957:in `visit_class'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:398:in `visit'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:526:in `block (2 levels) in visit_exps'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:3699:in `push_node'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:525:in `block in visit_exps'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:504:in `each'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:504:in `each_with_index'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:504:in `visit_exps'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:201:in `visit'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/formatter.rb:177:in `format'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/command.rb:146:in `format'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/command.rb:49:in `format_stdin'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/command.rb:38:in `run'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/lib/rufo/command.rb:12:in `run'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/gems/rufo-0.13.0/exe/rufo:4:in `<top (required)>'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/bin/rufo:25:in `load'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/bin/rufo:25:in `<main>'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/bin/ruby_executable_hooks:22:in `eval'
    from /home/sk8higher/.rvm/gems/ruby-3.1.2/bin/ruby_executable_hooks:22:in `<main>'

Changing the method to:

  def digest(string)
    cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST : BCrypt::Engine.cost
    BCrypt::Password.create(string, cost: cost)
  end

Stops the bug.

kzkn commented 1 year ago

rufo 0.13.0 does not support valueless hash syntax. Please try the latest version.