class RuboCop::Cop::Metrics::DGVZMethodLength
This cop checks if the length a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Private Instance Methods
blacklist()
click to toggle source
# File lib/dgvz_method_length.rb, line 30 def blacklist cop_config['Blacklist'] end
code_length(node)
click to toggle source
# File lib/dgvz_method_length.rb, line 24 def code_length(node) lines = node.source.lines.to_a[1..-2] || [] lines.count { |line| !dgvz_irrelevant_line(line) } end
dgvz_irrelevant_line(source_line)
click to toggle source
# File lib/dgvz_method_length.rb, line 38 def dgvz_irrelevant_line(source_line) source_line.blank? || (!count_comments? && comment_line?(source_line)) || logger_line?(source_line) end
logger_line?(source_line)
click to toggle source
# File lib/dgvz_method_length.rb, line 34 def logger_line?(source_line) blacklist.find { |o| source_line.include?(o) } end
message(length, max_length)
click to toggle source
# File lib/dgvz_method_length.rb, line 20 def message(length, max_length) format('Method has far too many lines. [%d/%d]', length, max_length) end
on_method_def(node, _method_name, _args, _body)
click to toggle source
# File lib/dgvz_method_length.rb, line 16 def on_method_def(node, _method_name, _args, _body) check_code_length(node) end