Class: HamlLint::Linter::IdNames

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

Overview

Checks for `id` attributes in specific cases on tags.

Constant Summary collapse

STYLIZED_NAMES =
{
  'camel_case' => 'camelCase',
  'lisp_case' => 'lisp-case',
  'pascal_case' => 'PascalCase',
  'snake_case' => 'snake_case',
}.freeze
STYLES =
{
  'camel_case' => /\A[a-z][\da-zA-Z]+\z/,
  'lisp_case' => /\A[\da-z-]+\z/,
  'pascal_case' => /\A[A-Z][\da-zA-Z]+\z/,
  'snake_case' => /\A[\da-z_]+\z/,
}.freeze

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


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

def visit_tag(node)
  return unless (id = node.tag_id)

  style = config['style'] || 'lisp_case'
  matcher = STYLES[style]
  record_lint(node, "`id` attribute must be in #{STYLIZED_NAMES[style]}") unless id =~ matcher
end