Rubocop error 'Class definition is too long ruby'

brg picture brg · Nov 22, 2013 · Viewed 10.1k times · Source

I am getting rubocop error 'Class definition is too long. [236/100]'. My class looks like below:

class SomeClassName
  include HelperModule
  attr_accessor :aaa, :bbb, :ccc

  .... methods .....
end

What might go wrong? The rubocop docs ClassLength says "length of a class exceeds some maximum value". What does it mean?

Answer

ron pastore picture ron pastore · Jan 8, 2014

Yes, this is because the overall lines are considered to be too many by rubucop. I agree classes shouldn't get too long but think that should ultimately be determined by: does the class have a single responsibility, are the methods concise enough, are there methods that could be shared via module, etc... The number/alert is a great warning though. If things in the class look OK, you can add # rubocop:disable ClassLength immediately above the class definition.