module Pluginscan # Responsible for printing a single finding on the command line class FindingPrinter < Printer def print(finding) finding = FindingView.new(finding) finding = IgnoredFindingView.new(finding) if finding.ignored @output.puts finding.source_line end end class FindingView < SimpleDelegator def source_line data = { lineno: lineno, line: highlight_matches(line.strip), } # pad line number to 5. Because some plugin files really are over 10k lines format " %5s: %{line}\n", data end private def highlight_matches(line) return line unless match # TODO: nil checks are evil! line.gsub match, match.color(:cyan) end end class IgnoredFindingView < SimpleDelegator def source_line i_symbol = "[I]".color(:red) super.gsub(/^ /, " #{i_symbol}") end end end