Module: WhyClasses::CorrectionPlan

Defined in:
lib/why_classes/correction_plan.rb

Overview

Decides which correctable offenses should actually be applied, given the configuration and whether --fix-unsafe was requested. Detection ("is there a corrector?") is separate from application ("should we run it?"): a rule can report a rewrite as available while the plan declines to apply it.

Class Method Summary collapse

Class Method Details

.applicable(offenses, configuration:, fix_unsafe: false) ⇒ Object



13
14
15
# File 'lib/why_classes/correction_plan.rb', line 13

def applicable(offenses, configuration:, fix_unsafe: false)
  offenses.select { |offense| apply?(offense, configuration, fix_unsafe) }
end

.apply?(offense, configuration, fix_unsafe) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/why_classes/correction_plan.rb', line 17

def apply?(offense, configuration, fix_unsafe)
  return false if offense.corrector.nil?

  # No Enabled re-check here: offenses only exist for rules that were active
  # (see Registry.active), so a --only-forced rule can still autocorrect.
  tier = Registry.fetch(offense.rule_name).tier
  case tier
  when :suggested
    configuration.autocorrect?(offense.rule_name)
  when :unsafe
    fix_unsafe
  else
    false
  end
end