Skip to content

Resolve all paths to absolute paths #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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