Class: HamlLint::Linter::ImplicitDiv

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

Overview

Checks for unnecessary uses of the `%div` prefix where a class name or ID already implies a div.

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

Methods included from HamlVisitor

#visit, #visit_children

Constructor Details

This class inherits a constructor from HamlLint::Linter

Instance Method Details

#visit_tag(node) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/haml_lint/linter/implicit_div.rb', line 9

def visit_tag(node)
  return unless node.tag_name == 'div'

  return unless node.static_classes.any? || node.static_ids.any?

  tag = node.source_code[/\s*([^\s={\(\[]+)/, 1]
  return unless tag.start_with?('%div')

  record_lint(node,
              "`#{tag}` can be written as `#{node.static_attributes_source}` " \
              'since `%div` is implicit')
end