Skip to content

Commit

Permalink
use absolute path when environment variable; RUBOCOP_CHECKSTYLE_FORMA…
Browse files Browse the repository at this point in the history
…TTER_ABSOLUTE_PATH is defined
  • Loading branch information
eitoball committed Apr 23, 2017
1 parent 5cd4e38 commit 338ce2d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/rubocop/formatter/checkstyle_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ def started(_target_file)
def file_finished(file, offences)
REXML::Element.new('file', @checkstyle).tap do |f|
path_name = file
path_name = relative_path(file) if defined?(relative_path)
path_name = relative_path(path_name) if !ENV.has_key?('RUBOCOP_CHECKSTYLE_FORMATTER_ABSOLUTE_PATH') && defined?(relative_path)
f.attributes['name'] = path_name
# f.attributes['name'] =
# defined?(PathUtil) ? PathUtil.relative_path(file) : file
add_offences(f, offences)
end
end
Expand Down
19 changes: 19 additions & 0 deletions spec/rubocop/formatter/checkstyle_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,25 @@ module Formatter
end
end
end

context 'RUBOCOP_CHECKSTYLE_FORMATTER_ABSOLUTE_PATH is defined' do
around do |example|
ENV['RUBOCOP_CHECKSTYLE_FORMATTER_ABSOLUTE_PATH'] = 'true'
example.run
ENV.delete('RUBOCOP_CHECKSTYLE_FORMATTER_ABSOLUTE_PATH')
end

it 'should use absolute path in name attribute of file tag' do
output = StringIO.new
formatter = described_class.new(output)
formatter.started(file)
formatter.file_finished(file, cop.respond_to?(:offenses) ? cop.offenses : cop.offences)
formatter.finished([file])
doc = REXML::Document.new(output.string)
file = REXML::XPath.first(doc, '/checkstyle/file')
expect(Pathname.new(file['name'])).to be_absolute
end
end
end
end
end

0 comments on commit 338ce2d

Please sign in to comment.