Class: EagerEye::AutoFixer

Inherits:
Object
  • Object
show all
Defined in:
lib/eager_eye/auto_fixer.rb

Instance Method Summary collapse

Constructor Details

#initialize(issues, interactive: true) ⇒ AutoFixer

Returns a new instance of AutoFixer.



5
6
7
8
9
# File 'lib/eager_eye/auto_fixer.rb', line 5

def initialize(issues, interactive: true)
  @issues = issues
  @interactive = interactive
  @files_cache = {}
end

Instance Method Details

#runObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/eager_eye/auto_fixer.rb', line 11

def run
  fixes = collect_fixes
  return puts "No auto-fixable issues found." if fixes.empty?

  if @interactive
    apply_interactively(fixes)
  else
    apply_all(fixes)
  end
end

#suggestObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/eager_eye/auto_fixer.rb', line 22

def suggest
  fixes = collect_fixes
  return puts "No auto-fixable issues found." if fixes.empty?

  fixes.group_by { |f| f[:file] }.each do |file, file_fixes|
    puts "\n#{file}:"
    file_fixes.each do |fix|
      puts "  Line #{fix[:line]}:"
      puts "    - #{fix[:original]}"
      puts "    + #{fix[:fixed]}"
    end
  end
end