module RuboCop::Cop::CodeLength
def build_code_length_calculator(node)
def build_code_length_calculator(node) Metrics::Utils::CodeLengthCalculator.new( node, processed_source, count_comments: count_comments?, foldable_types: count_as_one ) end
def check_code_length(node)
def check_code_length(node) # Skip costly calculation when definitely not needed return if node.line_count <= max_length calculator = build_code_length_calculator(node) length = calculator.calculate return if length <= max_length location = node.casgn_type? ? node.loc.name : node.source_range add_offense(location, message: message(length, max_length)) { self.max = length } end
def count_as_one
def count_as_one Array(cop_config['CountAsOne']).map(&:to_sym) end
def count_comments?
def count_comments? cop_config['CountComments'] end
def irrelevant_line(source_line)
def irrelevant_line(source_line) source_line.blank? || (!count_comments? && comment_line?(source_line)) end
def max_length
def max_length cop_config['Max'] end
def message(length, max_length)
def message(length, max_length) format(MSG, label: cop_label, length: length, max: max_length) end