class Rfix::Formatter
Constants
- NEWLINE
- NoSuchFileError
- PADDING
- SPACE
- SURROUNDING_LINES
Public Class Methods
new(output, options = EMPTY_HASH)
click to toggle source
Calls superclass method
# File lib/rfix/formatter.rb, line 52 def initialize(output, options = EMPTY_HASH) TTY::ProgressBar.new(":current/:total (:eta) [:bar]", output: output).then do |bar| super(output, output: output, options: options, params: options, progress: bar) end end
Public Instance Methods
file_finished(_file, offenses)
click to toggle source
@file [File] @offenses [Array<Offence>]
# File lib/rfix/formatter.rb, line 70 def file_finished(_file, offenses) @reported_offenses += offenses progress.advance end
finished(files)
click to toggle source
@files [Array<File>]
# File lib/rfix/formatter.rb, line 77 def finished(files) progress.finish mark_command_line reported_offenses.each do |offense| progress.log(NEWLINE) framed(offense) do report_line_with_highlight(offense) end rescue NoSuchFileError # NOP end report_summary(files) end
source_buffer()
click to toggle source
# File lib/rfix/formatter.rb, line 30 def source_buffer raise NoSuchFileError end
started(files)
click to toggle source
# File lib/rfix/formatter.rb, line 58 def started(files) progress.configure do |config| config.bar_format = :block config.total = files.count config.clear_head = true config.clear = true config.width = width end end
surround(value)
click to toggle source
# File lib/rfix/formatter.rb, line 24 def surround(value) value + self + value end
Private Instance Methods
arity()
click to toggle source
# File lib/rfix/formatter.rb, line 114 def arity method(:report_summary).super_method.arity end
correctable()
click to toggle source
# File lib/rfix/formatter.rb, line 151 def correctable reported_offenses.select(&:correctable?) end
corrected()
click to toggle source
# File lib/rfix/formatter.rb, line 147 def corrected reported_offenses.select(&:corrected?) end
framed(offense, &block)
click to toggle source
# File lib/rfix/formatter.rb, line 98 def framed(offense, &block) progress.log TTY::Box.frame({ width: width, padding: [PADDING, PADDING, 0, PADDING], title: { top_left: "#{offense.icon} #{offense.msg}".surround(SPACE), bottom_left: offense.clickable_path(repository.path)&.surround(SPACE), top_right: offense.cop_name.surround(SPACE) } }, &block) end
mark_command_line()
click to toggle source
# File lib/rfix/formatter.rb, line 118 def mark_command_line # progress.log "\e]1337;SetMark\a" end
offenses?()
click to toggle source
# File lib/rfix/formatter.rb, line 159 def offenses? reported_offenses.any? end
report_line_with_highlight(offense)
click to toggle source
# File lib/rfix/formatter.rb, line 122 def report_line_with_highlight(offense) location = offense.location buffer = location.source_buffer source = buffer.source line = location.line last_line = buffer.last_line min_line = [line - SURROUNDING_LINES * 2, 1].max max_line = [line + SURROUNDING_LINES * 2, last_line].min begin_index = buffer.line_range(min_line).begin_pos end_index = buffer.line_range(max_line).end_pos visible = begin_index...end_index highlight = location.to_range Highlighter.new( visible_lines: (min_line..max_line), highlight: highlight, visible: visible ).call(source) end
report_summary(files)
click to toggle source
Calls superclass method
# File lib/rfix/formatter.rb, line 110 def report_summary(files) super(*stats.insert(0, files.count).take(arity)) end
stats()
click to toggle source
# File lib/rfix/formatter.rb, line 155 def stats [reported_offenses.count, corrected.count, correctable.count] end
width()
click to toggle source
# File lib/rfix/formatter.rb, line 94 def width TTY::Screen.width end