14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/checkstyle_filter/git/cli.rb', line 14
def diff(commit_ish = nil)
data = \
if options[:data]
options[:data]
elsif options[:file]
File.read(options[:file])
elsif !$stdin.tty?
ARGV.clear
ARGF.read
end
abort if !data || data.empty?
command = ['git', 'diff', '--no-color', commit_ish].compact
git_diff, _, _ = Open3.capture3(*command)
parsed = ::CheckstyleFilter::Git::DiffParser.parse(git_diff)
require 'rexml/document'
document = REXML::Document.new data
document.elements.each('/checkstyle/file') do |file_element|
file_name = file_element.attribute('name').value
next unless file_element_file_in_git_diff?(file_name, parsed)
file_element.elements.each('error') do |error_element|
line = error_element.attribute('line') && error_element.attribute('line').value.to_i
if file_element_error_line_no_in_modified?(file_name, parsed, line)
error_element.remove
end
end
end
puts document.to_s
end
|