Class: HamlLint::Linter::ClassAttributeWithStaticValue
- Inherits:
-
HamlLint::Linter
- Object
- HamlLint::Linter
- HamlLint::Linter::ClassAttributeWithStaticValue
- 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
Instance Method Summary collapse
Methods included from HamlLint::LinterRegistry
extract_linters_from, included
Methods inherited from HamlLint::Linter
autocorrect_priority, autocorrect_safe?, #initialize, #name, ruby_parser, #run, #run_or_raise, supports_autocorrect?, #supports_autocorrect?
Methods included from HamlVisitor
Constructor Details
This class inherits a constructor from HamlLint::Linter
Instance Method Details
#visit_tag(node) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/haml_lint/linter/class_attribute_with_static_value.rb', line 27 def visit_tag(node) class_value = static_class_value(node.dynamic_attributes_sources) return unless class_value corrected = correct_class_attribute(node, class_value) record_lint(node, 'Avoid defining `class` in attributes hash ' \ 'for static class names', corrected: corrected) end |