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
- #generate_offense(klass, processed_source, tag, message = nil, replacement = nil) ⇒ Object
- #generate_offense_from_source_range(klass, source_range, message = nil, replacement = nil) ⇒ Object
- #simple_class_name ⇒ Object
- #tags(processed_source) ⇒ Object
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, = nil, replacement = nil) ||= 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, = nil, replacement = nil) ||= klass::MESSAGE offense = ["#{simple_class_name}:#{message}", source_range.source].join("\n") add_offense(source_range, offense, replacement) end |
#simple_class_name ⇒ Object
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 (processed_source) processed_source.parser.nodes_with_type(:tag).map { |tag_node| BetterHtml::Tree::Tag.from_node(tag_node) } end |