class HamlLint::Linter::ConsecutiveComments

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

Constants

COMMENT_DETECTOR

Public Instance Methods

visit_haml_comment(node) click to toggle source
# File lib/haml_lint/linter/consecutive_comments.rb, line 10
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 }
    record_lint(group.first,
                "#{group.count} consecutive comments can be merged into one")
  end
end

Private Instance Methods

possible_group(node) click to toggle source
# File lib/haml_lint/linter/consecutive_comments.rb, line 26
def possible_group(node)
  node.subsequents.unshift(node)
end
previously_reported?(node) click to toggle source
# File lib/haml_lint/linter/consecutive_comments.rb, line 30
def previously_reported?(node)
  reported_nodes.include?(node)
end
reported_nodes() click to toggle source
# File lib/haml_lint/linter/consecutive_comments.rb, line 34
def reported_nodes
  @reported_nodes ||= []
end