Module: ERBLint::Linters::Agent::CustomHelpers

Included in:
NoDirectEmoji, NoDirectSvgTag, NoSpecificAttributes, NoSpecificClasses
Defined in:
lib/erblint/agent/linters/custom_helpers.rb

Overview

Provides custom helper methods for ERB linting agents.

Instance Method Summary collapse

Instance Method Details

#generate_offense(klass, processed_source, tag, message = nil, replacement = nil) ⇒ Object



8
9
10
11
12
# File 'lib/erblint/agent/linters/custom_helpers.rb', line 8

def generate_offense(klass, processed_source, tag, message = nil, replacement = nil)
  message ||= klass::MESSAGE
  offense = ["#{simple_class_name}:#{message}", tag.node.loc.source].join("\n")
  add_offense(processed_source.to_source_range(tag.loc), offense, replacement)
end

#generate_offense_from_source_range(klass, source_range, message = nil, replacement = nil) ⇒ Object



14
15
16
17
18
# File 'lib/erblint/agent/linters/custom_helpers.rb', line 14

def generate_offense_from_source_range(klass, source_range, message = nil, replacement = nil)
  message ||= klass::MESSAGE
  offense = ["#{simple_class_name}:#{message}", source_range.source].join("\n")
  add_offense(source_range, offense, replacement)
end

#simple_class_nameObject



24
25
26
# File 'lib/erblint/agent/linters/custom_helpers.rb', line 24

def simple_class_name
  self.class.name.gsub("ERBLint::Linters::", "")
end

#tags(processed_source) ⇒ Object



20
21
22
# File 'lib/erblint/agent/linters/custom_helpers.rb', line 20

def tags(processed_source)
  processed_source.parser.nodes_with_type(:tag).map { |tag_node| BetterHtml::Tree::Tag.from_node(tag_node) }
end