Class: ERBLint::Linters::Agent::NoSpecificClasses

Inherits:
ERBLint::Linter
  • Object
show all
Includes:
ERBLint::LinterRegistry, CustomHelpers
Defined in:
lib/erblint/agent/linters/agent/no_specific_classes.rb

Overview

Linter that checks for forbidden CSS class names in ERB templates.

Defined Under Namespace

Classes: ConfigSchema

Constant Summary collapse

CLASS_ATTR_REGEX =
/class\s*=\s*["']([^"']+)["']/i
ERB_CLASS_REGEX =
/class\s*=\s*["']([^"']*<%[^>]*%>[^"']*)["']/i
DYNAMIC_CLASS_REGEX =
/class:\s*["']([^"']+)["']/

Instance Method Summary collapse

Methods included from CustomHelpers

#generate_offense, #generate_offense_from_source_range, #simple_class_name, #tags

Instance Method Details

#run(processed_source) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/erblint/agent/linters/agent/no_specific_classes.rb', line 27

def run(processed_source)
  return if @config.forbidden_classes.empty?

  file_content = processed_source.file_content

  scan_class_attributes(processed_source, file_content, CLASS_ATTR_REGEX)
  scan_class_attributes(processed_source, file_content, DYNAMIC_CLASS_REGEX)
  scan_erb_class_attributes(processed_source, file_content)
end