Class: Reek::CodeClimate::CodeClimateFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/reek/code_climate/code_climate_formatter.rb

Overview

Generates a hash in the structure specified by the Code Climate engine spec

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(warning) ⇒ CodeClimateFormatter

Returns a new instance of CodeClimateFormatter.



10
11
12
# File 'lib/reek/code_climate/code_climate_formatter.rb', line 10

def initialize(warning)
  @warning = warning
end

Instance Attribute Details

#warningObject (readonly, private)

Returns the value of attribute warning.



26
27
28
# File 'lib/reek/code_climate/code_climate_formatter.rb', line 26

def warning
  @warning
end

Instance Method Details

#categoriesObject (private)



36
37
38
# File 'lib/reek/code_climate/code_climate_formatter.rb', line 36

def categories
  ['Complexity']
end

#check_nameObject (private)



32
33
34
# File 'lib/reek/code_climate/code_climate_formatter.rb', line 32

def check_name
  warning.smell_type
end

#configurationObject (private)



59
60
61
# File 'lib/reek/code_climate/code_climate_formatter.rb', line 59

def configuration
  @configuration ||= CodeClimateConfiguration.load
end

#contentObject (private)



55
56
57
# File 'lib/reek/code_climate/code_climate_formatter.rb', line 55

def content
  configuration[warning.smell_type].fetch('content')
end

#descriptionObject (private)



28
29
30
# File 'lib/reek/code_climate/code_climate_formatter.rb', line 28

def description
  [warning.context, warning.message].join(' ')
end

#fingerprintObject (private)



51
52
53
# File 'lib/reek/code_climate/code_climate_formatter.rb', line 51

def fingerprint
  CodeClimateFingerprint.new(warning).compute
end

#locationObject (private)



40
41
42
43
44
45
# File 'lib/reek/code_climate/code_climate_formatter.rb', line 40

def location
  warning_lines = warning.lines
  CCEngine::Location::LineRange.new(
    path: warning.source,
    line_range: warning_lines.first..warning_lines.last)
end

#remediation_pointsObject (private)



47
48
49
# File 'lib/reek/code_climate/code_climate_formatter.rb', line 47

def remediation_points
  configuration[warning.smell_type].fetch('remediation_points')
end

#renderObject



14
15
16
17
18
19
20
21
22
# File 'lib/reek/code_climate/code_climate_formatter.rb', line 14

def render
  CCEngine::Issue.new(check_name: check_name,
                      description: description,
                      categories: categories,
                      location: location,
                      remediation_points: remediation_points,
                      fingerprint: fingerprint,
                      content: content).render
end