Class: ERBLint::Corrector

Inherits:
Object
  • Object
show all
Defined in:
lib/erb_lint/corrector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(processed_source, offenses) ⇒ Corrector

Returns a new instance of Corrector.



7
8
9
10
11
12
13
# File 'lib/erb_lint/corrector.rb', line 7

def initialize(processed_source, offenses)
  @processed_source = processed_source
  @offenses = offenses
  corrector = RuboCop::Cop::Corrector.new(@processed_source.source_buffer)
  correct!(corrector)
  @corrected_content = corrector.rewrite
end

Instance Attribute Details

#corrected_contentObject (readonly)

Returns the value of attribute corrected_content.



5
6
7
# File 'lib/erb_lint/corrector.rb', line 5

def corrected_content
  @corrected_content
end

#offensesObject (readonly)

Returns the value of attribute offenses.



5
6
7
# File 'lib/erb_lint/corrector.rb', line 5

def offenses
  @offenses
end

#processed_sourceObject (readonly)

Returns the value of attribute processed_source.



5
6
7
# File 'lib/erb_lint/corrector.rb', line 5

def processed_source
  @processed_source
end

Instance Method Details

#correct!(corrector) ⇒ Object



21
22
23
24
25
# File 'lib/erb_lint/corrector.rb', line 21

def correct!(corrector)
  corrections.each do |correction|
    correction.call(corrector)
  end
end

#correctionsObject



15
16
17
18
19
# File 'lib/erb_lint/corrector.rb', line 15

def corrections
  @corrections ||= @offenses.map do |offense|
    offense.linter.autocorrect(@processed_source, offense) if offense.linter.class.support_autocorrect?
  end.compact
end