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

#initialize, #name, #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



10
11
12
13
14
15
16
17
18
19
20
21
22
# 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