flyerhzm / rails_best_practices

a code metric tool for rails projects
http://rails-bestpractices.com
MIT License
4.16k stars 276 forks source link

`mark_parent_class_method_used` method traverses inheritance tree up indefinitely #290

Open maksar opened 7 years ago

maksar commented 7 years ago

We have such code in our legacy application:

module Public
  class ApplicationController < ApplicationController
    ...
  end
end

rails_best_practices-1.18.0/lib/rails_best_practices/core/methods.rb:57 #mark_parent_class_method_used method traverses inheritance tree up indefinitely. Ruby and Rails, however, handling situation just fine, assuming, that Public::ApplicationController inherits from ::ApplicationController

/Users/maksar/.rvm/gems/ruby-2.2.4/gems/rails_best_practices-1.18.0/lib/rails_best_practices/core/methods.rb:58:in `block in mark_parent_class_method_used': stack level too deep (SystemStackError)                                                    |
    from /Users/maksar/.rvm/gems/ruby-2.2.4/gems/rails_best_practices-1.18.0/lib/rails_best_practices/core/methods.rb:58:in `each'
    from /Users/maksar/.rvm/gems/ruby-2.2.4/gems/rails_best_practices-1.18.0/lib/rails_best_practices/core/methods.rb:58:in `find'
    from /Users/maksar/.rvm/gems/ruby-2.2.4/gems/rails_best_practices-1.18.0/lib/rails_best_practices/core/methods.rb:58:in `mark_parent_class_method_used'
    from /Users/maksar/.rvm/gems/ruby-2.2.4/gems/rails_best_practices-1.18.0/lib/rails_best_practices/core/methods.rb:60:in `mark_parent_class_method_used'
    from /Users/maksar/.rvm/gems/ruby-2.2.4/gems/rails_best_practices-1.18.0/lib/rails_best_practices/core/methods.rb:60:in `mark_parent_class_method_used'
    from /Users/maksar/.rvm/gems/ruby-2.2.4/gems/rails_best_practices-1.18.0/lib/rails_best_practices/core/methods.rb:60:in `mark_parent_class_method_used'
    from /Users/maksar/.rvm/gems/ruby-2.2.4/gems/rails_best_practices-1.18.0/lib/rails_best_practices/core/methods.rb:60:in `mark_parent_class_method_used'
    from /Users/maksar/.rvm/gems/ruby-2.2.4/gems/rails_best_practices-1.18.0/lib/rails_best_practices/core/methods.rb:60:in `mark_parent_class_method_used'
     ... 7704 levels...
    from /Users/maksar/.rvm/gems/ruby-2.2.4/bin/rails_best_practices:22:in `load'
    from /Users/maksar/.rvm/gems/ruby-2.2.4/bin/rails_best_practices:22:in `<main>'
    from /Users/maksar/.rvm/gems/ruby-2.2.4/bin/ruby_executable_hooks:15:in `eval'
    from /Users/maksar/.rvm/gems/ruby-2.2.4/bin/ruby_executable_hooks:15:in `<main>'
flyerhzm commented 7 years ago

@maksar I suggest you defining Public::ApplicationController as

module Public
  class ApplicationController < ::ApplicationController
    ...
  end
end
maksar commented 7 years ago

@flyerhzm That is exactly what I did to fix the error. Further more, I think construct class A < A should not be used. However, since ruby handles such situation well, probably RBP should too (at least have protection against eternal recursion).