Class: RubomaticHtml::Cop::Style::NoOnAttribute

Inherits:
Base
  • Object
show all
Defined in:
lib/rubomatic-html/cop/style/no_on_attribute.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#config, #file

Instance Method Summary collapse

Methods inherited from Base

department

Methods inherited from Base

abstract_cop?, allowed_config_transform, #initialize, name

Constructor Details

This class inherits a constructor from RubomaticHtml::Cop::Base

Instance Attribute Details

#html_attrString

Returns:

  • (String)


8
9
10
# File 'lib/rubomatic-html/cop/style/no_on_attribute.rb', line 8

def html_attr
  @html_attr
end

Instance Method Details

#run_for_line(line, index) ⇒ Object

See Also:

  • super


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rubomatic-html/cop/style/no_on_attribute.rb', line 11

def run_for_line(line, index)
  # `onclick:` or `onclick=`
  has_on_click = line.match?(/#{html_attr}[:=]/i)

  # `:onclick=>` or `:onclick =>`
  has_on_click ||= line.match?(/:#{html_attr} ?=>/i)

  # `'onclick'=>` or `'onclick' =>`
  has_on_click ||= line.match?(/'#{html_attr}' ?=>/i)

  # `"onclick"=>` or `"onclick" =>`
  has_on_click ||= line.match?(/"#{html_attr}" ?=>/i)

  return unless has_on_click

  puts("#{file}:#{index}: might use an #{html_attr} attribute")
end