Class: RuboCop::Cop::Yoshiki::Style::NestedHtmlOptionKeys::Forest

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

Overview

Walk pairs into a nestable entry list.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, prefixes) ⇒ Forest

Returns a new instance of Forest.



35
36
37
38
39
40
41
42
# File 'lib/rubocop/cop/yoshiki/style/nested_html_option_keys/rewriter.rb', line 35

def initialize node, prefixes
  @prefixes     = prefixes
  @direct       = []
  @all_offenses = []
  @mutated      = false
  @tree         = Tree.new(self)
  @entries      = build(node, mode_for(node), true)
end

Instance Attribute Details

#all_offensesObject (readonly)

Returns the value of attribute all_offenses.



33
34
35
# File 'lib/rubocop/cop/yoshiki/style/nested_html_option_keys/rewriter.rb', line 33

def all_offenses
  @all_offenses
end

#directObject (readonly)

Returns the value of attribute direct.



33
34
35
# File 'lib/rubocop/cop/yoshiki/style/nested_html_option_keys/rewriter.rb', line 33

def direct
  @direct
end

#entriesObject (readonly)

Returns the value of attribute entries.



33
34
35
# File 'lib/rubocop/cop/yoshiki/style/nested_html_option_keys/rewriter.rb', line 33

def entries
  @entries
end

Instance Method Details

#build(node, mode, direct) ⇒ Object



52
53
54
55
56
# File 'lib/rubocop/cop/yoshiki/style/nested_html_option_keys/rewriter.rb', line 52

def build node, mode, direct
  node.children.each_with_object([]) do |child, entries|
    push(entries, child, mode, direct)
  end
end

#mutated!Object



48
49
50
# File 'lib/rubocop/cop/yoshiki/style/nested_html_option_keys/rewriter.rb', line 48

def mutated!
  @mutated = true
end

#mutated?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/rubocop/cop/yoshiki/style/nested_html_option_keys/rewriter.rb', line 44

def mutated?
  @mutated
end

#note_offense(pair, direct) ⇒ Object



62
63
64
65
66
# File 'lib/rubocop/cop/yoshiki/style/nested_html_option_keys/rewriter.rb', line 62

def note_offense pair, direct
  range = pair.key.source_range
  @all_offenses << range
  @direct << range if direct
end

#prefix?(name) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/rubocop/cop/yoshiki/style/nested_html_option_keys/rewriter.rb', line 58

def prefix? name
  name && @prefixes.include?(name)
end