Module: Sloplint::Output

Defined in:
lib/sloplint/output.rb

Class Method Summary collapse

Class Method Details

.format_human(notes) ⇒ Object

proselint-style "full" text: one note per line, with excerpt + suggestion.



10
11
12
13
14
15
16
17
18
19
# File 'lib/sloplint/output.rb', line 10

def format_human(notes)
  return "" if notes.empty?

  notes.map do |n|
    head = "#{n.path}:#{n.line}:#{n.column}: #{n.severity} #{n.rule}  #{n.message}"
    excerpt = "    excerpt: #{n.excerpt}"
    fix = "    fix: #{n.suggestion}"
    [head, excerpt, fix].join("\n")
  end.join("\n\n")
end

.format_json(notes, by_path: false) ⇒ Object

JSON: an array of notes, or an object keyed by path when >1 file was scanned.



22
23
24
25
26
27
28
29
# File 'lib/sloplint/output.rb', line 22

def format_json(notes, by_path: false)
  if by_path
    grouped = notes.group_by(&:path).transform_values { |ns| ns.map { |n| note_hash(n) } }
    JSON.pretty_generate(grouped)
  else
    JSON.pretty_generate(notes.map { |n| note_hash(n) })
  end
end

.note_hash(note) ⇒ Object



31
32
33
34
35
# File 'lib/sloplint/output.rb', line 31

def note_hash(note)
  h = note.to_h
  h.delete(:count) if h[:count].nil?
  h
end