ruby-formatter / rufo

The Ruby Formatter
MIT License
900 stars 56 forks source link

bug #304

Closed BraisonCrece closed 1 year ago

BraisonCrece commented 1 year ago
/home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:3898:in `bug': Expected token on_int, not on_lparen at [[10, 14], :on_lparen, "(", BEG|LABEL] (Rufo::Bug)
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:3893:in `check'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:3450:in `consume_token'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:211:in `visit'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:2459:in `visit_range'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:422:in `visit'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:3017:in `block in visit_when'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:3703:in `indent'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:3012:in `visit_when'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:388:in `visit'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:2987:in `visit_case'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:386:in `visit'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:520:in `block (2 levels) in visit_exps'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:4019:in `push_node'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:519:in `block in visit_exps'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:498:in `each'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:498:in `each_with_index'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:498:in `visit_exps'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:3783:in `block in indent_body'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:3707:in `indent'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:3782:in `indent_body'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:1594:in `visit_bodystmt'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:376:in `visit'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:2122:in `visit_def_from_name'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:2035:in `block in visit_def'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:4027:in `push_hash'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:2034:in `visit_def'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:406:in `visit'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:520:in `block (2 levels) in visit_exps'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:4019:in `push_node'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:519:in `block in visit_exps'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:498:in `each'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:498:in `each_with_index'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:498:in `visit_exps'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:3783:in `block in indent_body'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:3707:in `indent'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:3782:in `indent_body'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:1594:in `visit_bodystmt'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:376:in `visit'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:1990:in `block in visit_class'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:4034:in `push_type'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:1974:in `visit_class'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:394:in `visit'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:520:in `block (2 levels) in visit_exps'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:4019:in `push_node'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:519:in `block in visit_exps'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:498:in `each'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:498:in `each_with_index'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:498:in `visit_exps'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:201:in `visit'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/formatter.rb:177:in `format'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/command.rb:146:in `format'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/command.rb:49:in `format_stdin'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/command.rb:38:in `run'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/lib/rufo/command.rb:12:in `run'
    from /home/braisoncrece/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rufo-0.16.0/exe/rufo:4:in `<top (required)>'
    from /home/braisoncrece/.rbenv/versions/3.1.2/bin/rufo:25:in `load'
    from /home/braisoncrece/.rbenv/versions/3.1.2/bin/rufo:25:in `<main>'

And that is the code:

The error was shown when I wrote this line in the first method rating in (9..0)

  class Rating < ApplicationRecord
  belongs_to :person
  validates :rating, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 10 }

  def promoter?
    rating in (9..10)
  end

  def pasive?
    rating in (7..8)
  end

  def detractor?
    rating in (0..6)
  end

  after_create do
    person.update(score: rating)
  end
end
kzkn commented 1 year ago

Thanks for the reporting!