Module: RuboCop::Cop::CodeLength
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
::RuboCop::ExcludeLimit
|
|
Defined in: | lib/rubocop/cop/mixin/code_length.rb |
Overview
Common functionality for checking length of code segments.
Constant Summary
-
MSG =
# File 'lib/rubocop/cop/mixin/code_length.rb', line 9'%<label>s has too many lines. [%<length>d/%<max>d]'
Class Method Summary
::RuboCop::ExcludeLimit
- Extended
exclude_limit | Sets up a configuration option to have an exclude limit tracked. |
transform |
Instance Attribute Summary
- #count_comments? ⇒ Boolean readonly private
Instance Method Summary
- #build_code_length_calculator(node) private
- #check_code_length(node) private
- #count_as_one private
-
#irrelevant_line(source_line)
private
Returns true for lines that shall not be included in the count.
- #location(node) private
- #max_length private
- #message(length, max_length) private
Instance Attribute Details
#count_comments? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'lib/rubocop/cop/mixin/code_length.rb', line 23
def count_comments? cop_config['CountComments'] end
Instance Method Details
#build_code_length_calculator(node) (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/code_length.rb', line 49
def build_code_length_calculator(node) Metrics::Utils::CodeLengthCalculator.new( node, processed_source, count_comments: count_comments?, foldable_types: count_as_one ) end
#check_code_length(node) (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/code_length.rb', line 31
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 = location(node) add_offense(location, message: (length, max_length)) { self.max = length } end
#count_as_one (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/code_length.rb', line 27
def count_as_one Array(cop_config['CountAsOne']).map(&:to_sym) end
#irrelevant_line(source_line) (private)
Returns true for lines that shall not be included in the count.
# File 'lib/rubocop/cop/mixin/code_length.rb', line 45
def irrelevant_line(source_line) source_line.blank? || (!count_comments? && comment_line?(source_line)) end
#location(node) (private)
[ GitHub ]#max_length (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/code_length.rb', line 19
def max_length cop_config['Max'] end
#message(length, max_length) (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/code_length.rb', line 15
def (length, max_length) format(MSG, label: cop_label, length: length, max: max_length) end