Module: MetzScan::Commands::Scan::ProjectAnalyzerOffenses

Defined in:
lib/metz_scan/commands/scan/project_analyzer_offenses.rb

Defined Under Namespace

Classes: OffenseSet

Class Method Summary collapse

Class Method Details

.add_project_analyzer_metadata(metadata, finding, occurrence) ⇒ Object



54
55
56
57
58
59
# File 'lib/metz_scan/commands/scan/project_analyzer_offenses.rb', line 54

def (, finding, occurrence)
   = ProjectAnalyzerMetadata.(finding)
  return  if .empty?

  .merge("project_analyzer" => .merge((occurrence)))
end

.basic_offense_metadata(finding) ⇒ Object



44
45
46
47
# File 'lib/metz_scan/commands/scan/project_analyzer_offenses.rb', line 44

def (finding)
  { "cop_name" => finding.rule_id, "message" => finding.message,
    "severity" => "refactor", "corrected" => false, "correctable" => false }
end

.build(findings) ⇒ Object



13
14
15
16
# File 'lib/metz_scan/commands/scan/project_analyzer_offenses.rb', line 13

def build(findings)
  entries = entries_for(findings)
  OffenseSet.new(by_path: offenses_by_path(entries), offenses: entries.map { |entry| entry.fetch(:offense) })
end

.common_offense_metadata(finding) ⇒ Object



40
41
42
# File 'lib/metz_scan/commands/scan/project_analyzer_offenses.rb', line 40

def (finding)
  (finding).merge((finding))
end

.entries_for(findings) ⇒ Object



18
19
20
# File 'lib/metz_scan/commands/scan/project_analyzer_offenses.rb', line 18

def entries_for(findings)
  findings.flat_map { |finding| offenses_for(finding) }
end

.explanation_metadata(finding) ⇒ Object



49
50
51
52
# File 'lib/metz_scan/commands/scan/project_analyzer_offenses.rb', line 49

def (finding)
  { "why_it_matters" => finding.why_it_matters, "fix_safety" => "manual",
    "suggested_next_moves" => suggested_next_moves_for(finding) }
end

.location_hash(line) ⇒ Object



72
73
74
75
76
# File 'lib/metz_scan/commands/scan/project_analyzer_offenses.rb', line 72

def location_hash(line)
  line ||= 1
  { "start_line" => line, "start_column" => 1, "last_line" => line,
    "last_column" => 1, "length" => 1, "line" => line, "column" => 1 }
end

.locations_for(finding) ⇒ Object



28
29
30
# File 'lib/metz_scan/commands/scan/project_analyzer_offenses.rb', line 28

def locations_for(finding)
  Array(finding.report_occurrences).compact.uniq
end

.offense_for(finding, occurrence) ⇒ Object



32
33
34
# File 'lib/metz_scan/commands/scan/project_analyzer_offenses.rb', line 32

def offense_for(finding, occurrence)
  (finding, occurrence).merge("location" => location_hash(occurrence.report_line))
end

.offense_metadata(finding, occurrence) ⇒ Object



36
37
38
# File 'lib/metz_scan/commands/scan/project_analyzer_offenses.rb', line 36

def (finding, occurrence)
  ((finding), finding, occurrence)
end

.offenses_by_path(entries) ⇒ Object



78
79
80
81
# File 'lib/metz_scan/commands/scan/project_analyzer_offenses.rb', line 78

def offenses_by_path(entries)
  entries.group_by { |entry| entry.fetch(:path) }
         .transform_values { |grouped_entries| grouped_entries.map { |entry| entry.fetch(:offense) } }
end

.offenses_for(finding) ⇒ Object



22
23
24
25
26
# File 'lib/metz_scan/commands/scan/project_analyzer_offenses.rb', line 22

def offenses_for(finding)
  locations_for(finding).map do |location|
    { path: location.path, offense: offense_for(finding, location) }
  end
end

.report_location_metadata(occurrence) ⇒ Object



61
62
63
64
# File 'lib/metz_scan/commands/scan/project_analyzer_offenses.rb', line 61

def (occurrence)
  { "report_location" => { "line_source" => occurrence.line_source,
                           "context" => occurrence.context }.compact }
end

.suggested_next_moves_for(finding) ⇒ Object



66
67
68
69
70
# File 'lib/metz_scan/commands/scan/project_analyzer_offenses.rb', line 66

def suggested_next_moves_for(finding)
  return [] unless finding.respond_to?(:suggested_next_moves)

  Array(finding.suggested_next_moves).map(&:to_s)
end