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' }

But will allow invalid class names for templating:

%tag{ class: '{{ template-var }}' }

Constant Summary collapse

STATIC_TYPES =
%i[str sym].freeze
VALID_CLASS_REGEX =
/^-?[_a-zA-Z]+[_a-zA-Z0-9-]*$/

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_tag(node) ⇒ Object



25
26
27
28
29
30
# File 'lib/haml_lint/linter/class_attribute_with_static_value.rb', line 25

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

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