Class: HamlLint::Linter::ClassAttributeWithStaticValue

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

Overview

Checks for class attributes defined in tag attribute hash with static values.

For example, it will prefer this:

%tag.class-name

…over:

%tag{ class: 'class-name' }

Constant Summary collapse

STATIC_TYPES =
[:str, :sym]
STATIC_CLASSES =
[String, Symbol]

Instance Attribute Summary

Attributes inherited from HamlLint::Linter

#lints, #parser

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


18
19
20
21
22
23
# File 'lib/haml_lint/linter/class_attribute_with_static_value.rb', line 18

def visit_tag(node)
  return unless contains_class_attribute?(node.dynamic_attributes_sources)

  add_lint(node, 'Avoid defining `class` in attributes hash ' \
                 'for static class names')
end