Reputation: 2895
In our project rubocop.yml
we have following check for number of lines in a class:
ClassLength:
Max: 150 # Default 100
There's a file in lib/utils/foo.rb
which is already more than 200 lines. If I run rubocop
inspection on master
branch then rubocop runs fine without any errors.
Now, in my feature/cool_feature
branch I added 5 lines to this lib/utils/foo.rb
class. Now if I run rubocop
in my branch it fails with an following error:
Offenses:
lib/utils/foo.rb:1:1: C: Class has too many lines. [151/150]
Upvotes: 1
Views: 284
Reputation: 1324218
bbatsov/rubocop/lib/rubocop/cop/metrics/class_length.rb
calls check_code_length(node)
, which calls code_length(node)
target_line_numbers = body_line_numbers -
line_numbers_of_inner_nodes(node, :module, :class)
target_line_numbers.reduce(0) do |length, line_number|
source_line = processed_source[line_number]
next length if irrelevant_line(source_line)
That means it will only count relevant lines (non-empty, non-comment)
So check if the file in master
actually has more than 150 non-empty, non-comment lines.
See "Rubocop error 'Class definition is too long ruby'" for more.
Upvotes: 1