Class: DiffCop

Inherits:
Object
  • Object
show all
Defined in:
lib/diff_cop.rb,
lib/diff_cop/version.rb

Constant Summary collapse

VERSION =
'0.1.0'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#lint_resultsObject

Returns the value of attribute lint_results.



6
7
8
# File 'lib/diff_cop.rb', line 6

def lint_results
  @lint_results
end

#patchesObject

Returns the value of attribute patches.



6
7
8
# File 'lib/diff_cop.rb', line 6

def patches
  @patches
end

#raw_lint_resultsObject

Returns the value of attribute raw_lint_results.



6
7
8
# File 'lib/diff_cop.rb', line 6

def raw_lint_results
  @raw_lint_results
end

Instance Method Details

#print!Object

take the generated lint results and print the relevant offenses to stdout (CLI)



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/diff_cop.rb', line 22

def print!
  fail 'must run #start before printing' unless @lint_results

  if @lint_results.empty?
    puts "\nYou're good! Rubocop has no offenses to report.\n"
    return true
  end

  puts <<-MSG

DiffCop Offenses:
=====================

#{generate_messages.join("\n\n")}

MSG

  false
end

#startObject

generate patches, run the linter and filter to only relevant results



9
10
11
12
13
14
15
16
17
18
# File 'lib/diff_cop.rb', line 9

def start
  @patches = generate_patches.group_by(&:file)
  @raw_lint_results = parsed_raw_lint_results(patches.keys)
  @lint_results = filter_raw_lint_results(
    raw_lint_results['files'] || [],
    patches
  )

  self
end