Class: HamlLint::Linter::ConsecutiveComments

Inherits:
HamlLint::Linter show all
Includes:
HamlLint::LinterRegistry
Defined in:
lib/haml_lint/linter/consecutive_comments.rb

Overview

Checks for multiple lines of code comments that can be condensed.

Constant Summary collapse

COMMENT_DETECTOR =
->(child) { child.type == :haml_comment }

Instance Attribute Summary

Attributes inherited from HamlLint::Linter

#lints

Instance Method Summary collapse

Methods included from HamlLint::LinterRegistry

extract_linters_from, included

Methods inherited from HamlLint::Linter

autocorrect_priority, autocorrect_safe?, #initialize, #name, ruby_parser, #run, #run_or_raise, supports_autocorrect?, #supports_autocorrect?

Methods included from HamlVisitor

#visit, #visit_children

Constructor Details

This class inherits a constructor from HamlLint::Linter

Instance Method Details

#visit_haml_comment(node) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/haml_lint/linter/consecutive_comments.rb', line 13

def visit_haml_comment(node)
  return if previously_reported?(node)

  HamlLint::Utils.for_consecutive_items(
    possible_group(node),
    COMMENT_DETECTOR,
    config['max_consecutive'] + 1,
  ) do |group|
    group.each { |group_node| reported_nodes << group_node }
    corrected = correct_group(group)
    record_lint(group.first,
                "#{group.count} consecutive comments can be merged into one",
                corrected: corrected)
  end
end