Skip to content

Commit

Permalink
Merge pull request #51 from codeclimate/will/file-paths
Browse files Browse the repository at this point in the history
Resolve all paths to absolute paths
  • Loading branch information
wfleming committed Feb 16, 2016
2 parents cc0acc3 + 997d24f commit e27bb9f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/cc/engine/file_list_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,24 @@ def exclude_due_to_config?(path)
end

def include_based_files_to_inspect
@include_paths.map do |path|
if path =~ %r{/$}
absolute_include_paths.flat_map do |path|
if Dir.exist?(path)
rubocop_runner.send(:find_target_files, [path])
elsif rubocop_file_to_include?(path)
path
end
end.flatten.compact
end.compact
end

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

def absolute_include_paths
@include_paths.map { |path| Pathname.new(path).realpath.to_s }
end

def rubocop_file_to_include?(file)
if file =~ /\.rb$/
true
Expand Down
31 changes: 31 additions & 0 deletions spec/cc/engine/rubocop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,37 @@ def method
expect(includes_check?(output, "Lint/UselessAssignment")).to be false
end

it "respects excludes in an inherit_from directive" do
create_source_file("foo.rb", <<-EORUBY)
def method
unused = "x"
return false
end
EORUBY
create_source_file("bar.rb", <<-EORUBY)
def method
unused = 42
return true
end
EORUBY

create_source_file(
".rubocop.yml",
"inherit_from: .rubocop_todo.yml\nAllCops:\n DisabledByDefault: true\nLint/UselessAssignment:\n Enabled: true\n"
)
create_source_file(
".rubocop_todo.yml",
"Lint/UselessAssignment:\n Exclude:\n - bar.rb\n"
)

output = run_engine("include_paths" => ["foo.rb", "bar.rb"])
issues = output.split("\0").map { |istr| JSON.parse(istr) }
lint_issues = issues.select { |issue| issue["check_name"] == "Rubocop/Lint/UselessAssignment" }

expect(lint_issues.detect { |i| i["location"]["path"] == "foo.rb" }).to be_present
expect(lint_issues.detect { |i| i["location"]["path"] == "bar.rb" }).to be_nil
end

it "reads a file with a #!.*ruby declaration at the top" do
create_source_file("my_script", <<-EORUBY)
#!/usr/bin/env ruby
Expand Down

0 comments on commit e27bb9f

Please sign in to comment.