Class: RuboCop::Cop::Yoshiki::Style::NestedHtmlOptionKeys::Rewriter

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/cop/yoshiki/style/nested_html_option_keys/rewriter.rb

Overview

Rebuild a hash with hyphenated data/aria keys nested.

Instance Method Summary collapse

Constructor Details

#initialize(node, prefixes) ⇒ Rewriter

Returns a new instance of Rewriter.



10
11
12
13
14
# File 'lib/rubocop/cop/yoshiki/style/nested_html_option_keys/rewriter.rb', line 10

def initialize node, prefixes
  @node    = node
  @forest  = Forest.new(node, prefixes)
  @entries = @forest.entries
end

Instance Method Details

#changed?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/rubocop/cop/yoshiki/style/nested_html_option_keys/rewriter.rb', line 20

def changed?
  @forest.mutated? && replacement != @node.source
end

#offensesObject



16
17
18
# File 'lib/rubocop/cop/yoshiki/style/nested_html_option_keys/rewriter.rb', line 16

def offenses
  changed? ? @forest.all_offenses : @forest.direct
end

#replacementObject



24
25
26
# File 'lib/rubocop/cop/yoshiki/style/nested_html_option_keys/rewriter.rb', line 24

def replacement
  @replacement ||= Printer.new.render(@node, @entries)
end