Class: HamlLint::Linter::SpaceInsideHashAttributes

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

Overview

Checks for spaces inside the braces of hash attributes (e.g. `%tag{ lang: en }` vs `%tagen`).

Constant Summary collapse

STYLE =
{
  'no_space' => {
    start_regex: /\A\{[^ ]/,
    end_regex: /[^ ]\}\z/,
    start_message: 'Hash attribute should start with no space after the opening brace',
    end_message: 'Hash attribute should end with no space before the closing brace'
  },
  'space' => {
    start_regex: /\A\{ [^ ]/,
    end_regex:  /[^ ] \}\z/,
    start_message: 'Hash attribute should start with one space after the opening brace',
    end_message: 'Hash attribute should end with one space before the closing brace'
  }
}

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


22
23
24
25
26
27
28
29
30
# File 'lib/haml_lint/linter/space_inside_hash_attributes.rb', line 22

def visit_tag(node)
  return unless node.hash_attributes?

  style = STYLE[config['style'] == 'no_space' ? 'no_space' : 'space']
  source = node.hash_attributes_source

  add_lint(node, style[:start_message]) unless source =~ style[:start_regex]
  add_lint(node, style[:end_message]) unless source =~ style[:end_regex]
end