diff --git a/lib/rubocop/git/commit_file.rb b/lib/rubocop/git/commit_file.rb index 1123796..3b3b3a7 100644 --- a/lib/rubocop/git/commit_file.rb +++ b/lib/rubocop/git/commit_file.rb @@ -6,6 +6,10 @@ def initialize(file, commit) @commit = commit end + def absolute_path + @file.absolute_path + end + def filename @file.filename end diff --git a/lib/rubocop/git/pseudo_resource.rb b/lib/rubocop/git/pseudo_resource.rb index a9498e5..8cbe644 100644 --- a/lib/rubocop/git/pseudo_resource.rb +++ b/lib/rubocop/git/pseudo_resource.rb @@ -1,11 +1,19 @@ module RuboCop module Git class PseudoResource - attr_reader :filename, :patch + attr_reader :patch, :pwd, :file_relative_path - def initialize(filename) - @filename = filename - @patch = '' + alias_method :filename, :file_relative_path + + def initialize(file_relative_path, pwd = Dir.pwd) + @file_relative_path = file_relative_path + @pwd = pwd + @patch = '' + end + + def absolute_path + filename + File.join(pwd, filename) end def status diff --git a/lib/rubocop/git/style_checker.rb b/lib/rubocop/git/style_checker.rb index 22bf63f..6de6c00 100644 --- a/lib/rubocop/git/style_checker.rb +++ b/lib/rubocop/git/style_checker.rb @@ -13,7 +13,7 @@ def initialize(modified_files, def violations file_violations = @modified_files.map do |modified_file| - FileViolation.new(modified_file.filename, offenses(modified_file)) + FileViolation.new(modified_file.absolute_path, offenses(modified_file)) end file_violations.select do |file_violation| diff --git a/lib/rubocop/git/style_guide.rb b/lib/rubocop/git/style_guide.rb index d9ec13e..b1a8cff 100644 --- a/lib/rubocop/git/style_guide.rb +++ b/lib/rubocop/git/style_guide.rb @@ -30,19 +30,19 @@ def ignored_file?(file) end def excluded_file?(file) - config.file_to_exclude?(file.filename) + config.file_to_exclude?(file.absolute_path) end def parse_source(file) rubocop_version = Gem::Version.new(RuboCop::Version::STRING) if rubocop_version < Gem::Version.new('0.36.0') - RuboCop::ProcessedSource.new(file.content, file.filename) + RuboCop::ProcessedSource.new(file.content, file.absolute_path) elsif rubocop_version < Gem::Version.new('0.41.0') RuboCop::ProcessedSource.new(file.content, - target_ruby_version, file.filename) + target_ruby_version, file.absolute_path) else RuboCop::ProcessedSource.new(file.content, - config.target_ruby_version, file.filename) + config.target_ruby_version, file.absolute_path) end end