class SimpleCovLinterFormatter::TextLinesFilter
Public Class Methods
new(text_lines)
click to toggle source
# File lib/simplecov_linter_formatter/text_lines_filter.rb, line 3 def initialize(text_lines) @text_lines = text_lines end
Public Instance Methods
filter()
click to toggle source
# File lib/simplecov_linter_formatter/text_lines_filter.rb, line 7 def filter return [] if text_content == "" return filter_with_reviewdog if reviewdog? filter_with_git_status end
Private Instance Methods
efm_param()
click to toggle source
# File lib/simplecov_linter_formatter/text_lines_filter.rb, line 24 def efm_param %w{%f %l %c %m}.join(SimpleCovLinterFormatter::LINE_SECTIONS_DIVIDER) end
filter_with_git_status()
click to toggle source
# File lib/simplecov_linter_formatter/text_lines_filter.rb, line 28 def filter_with_git_status status_files = status_to_lines(`git status --porcelain`) regexp = /#{status_files.join('|')}/ @text_lines.grep(regexp) end
filter_with_reviewdog()
click to toggle source
# File lib/simplecov_linter_formatter/text_lines_filter.rb, line 20 def filter_with_reviewdog `echo "#{text_content}" | reviewdog -efm="#{efm_param}" -diff="git diff"`.to_s.split("\n") end
reviewdog?()
click to toggle source
# File lib/simplecov_linter_formatter/text_lines_filter.rb, line 16 def reviewdog? silence_stream($stdout) { !!system("reviewdog --version") } end
silence_stream(stream) { || ... }
click to toggle source
# File lib/simplecov_linter_formatter/text_lines_filter.rb, line 45 def silence_stream(stream) old_stream = stream.dup stream.reopen(File::NULL) stream.sync = true yield ensure stream.reopen(old_stream) old_stream.close end
status_to_lines(status)
click to toggle source
# File lib/simplecov_linter_formatter/text_lines_filter.rb, line 34 def status_to_lines(status) status.split("\n").map do |change| file = change.split(" ").last file.end_with?("/") ? nil : file end.compact end
text_content()
click to toggle source
# File lib/simplecov_linter_formatter/text_lines_filter.rb, line 41 def text_content @text_content ||= @text_lines.join("\n") end