Skip to content

Commit e27bb9f

Browse files
committed
Merge pull request #51 from codeclimate/will/file-paths
Resolve all paths to absolute paths
2 parents cc0acc3 + 997d24f commit e27bb9f

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

lib/cc/engine/file_list_resolver.rb

+7-3
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,24 @@ def exclude_due_to_config?(path)
2929
end
3030

3131
def include_based_files_to_inspect
32-
@include_paths.map do |path|
33-
if path =~ %r{/$}
32+
absolute_include_paths.flat_map do |path|
33+
if Dir.exist?(path)
3434
rubocop_runner.send(:find_target_files, [path])
3535
elsif rubocop_file_to_include?(path)
3636
path
3737
end
38-
end.flatten.compact
38+
end.compact
3939
end
4040

4141
def local_path(path)
4242
realpath = Pathname.new(@root).realpath.to_s
4343
path.gsub(%r{^#{realpath}/}, '')
4444
end
4545

46+
def absolute_include_paths
47+
@include_paths.map { |path| Pathname.new(path).realpath.to_s }
48+
end
49+
4650
def rubocop_file_to_include?(file)
4751
if file =~ /\.rb$/
4852
true

spec/cc/engine/rubocop_spec.rb

+31
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,37 @@ def method
6262
expect(includes_check?(output, "Lint/UselessAssignment")).to be false
6363
end
6464

65+
it "respects excludes in an inherit_from directive" do
66+
create_source_file("foo.rb", <<-EORUBY)
67+
def method
68+
unused = "x"
69+
return false
70+
end
71+
EORUBY
72+
create_source_file("bar.rb", <<-EORUBY)
73+
def method
74+
unused = 42
75+
return true
76+
end
77+
EORUBY
78+
79+
create_source_file(
80+
".rubocop.yml",
81+
"inherit_from: .rubocop_todo.yml\nAllCops:\n DisabledByDefault: true\nLint/UselessAssignment:\n Enabled: true\n"
82+
)
83+
create_source_file(
84+
".rubocop_todo.yml",
85+
"Lint/UselessAssignment:\n Exclude:\n - bar.rb\n"
86+
)
87+
88+
output = run_engine("include_paths" => ["foo.rb", "bar.rb"])
89+
issues = output.split("\0").map { |istr| JSON.parse(istr) }
90+
lint_issues = issues.select { |issue| issue["check_name"] == "Rubocop/Lint/UselessAssignment" }
91+
92+
expect(lint_issues.detect { |i| i["location"]["path"] == "foo.rb" }).to be_present
93+
expect(lint_issues.detect { |i| i["location"]["path"] == "bar.rb" }).to be_nil
94+
end
95+
6596
it "reads a file with a #!.*ruby declaration at the top" do
6697
create_source_file("my_script", <<-EORUBY)
6798
#!/usr/bin/env ruby

0 commit comments

Comments
 (0)