Skip to content

Drop support for "exclude_paths" in engine config #53

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
28 changes: 2 additions & 26 deletions lib/cc/engine/file_list_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,11 @@ module Engine
class FileListResolver
def initialize(root:, engine_config: {}, config_store:)
@root = root
@exclude_paths = engine_config["exclude_paths"] || []
@include_paths = engine_config["include_paths"]
@include_paths = engine_config["include_paths"] || ["./"]
@config_store = config_store
end

def expanded_list
if @include_paths
include_based_files_to_inspect
else
exclude_based_files_to_inspect
end
end

private

def exclude_based_files_to_inspect
rubocop_runner.send(:find_target_files, []).reject do |path|
exclude_due_to_config?(path)
end
end

def exclude_due_to_config?(path)
@exclude_paths.include?(local_path(path))
end

def include_based_files_to_inspect
absolute_include_paths.flat_map do |path|
if Dir.exist?(path)
rubocop_runner.send(:find_target_files, [path])
Expand All @@ -38,10 +17,7 @@ def include_based_files_to_inspect
end.compact
end

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

def absolute_include_paths
@include_paths.map { |path| Pathname.new(path).realpath.to_s }
Expand Down
39 changes: 0 additions & 39 deletions spec/cc/engine/rubocop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,45 +128,6 @@ def method
expect(includes_check?(output, "Lint/UselessAssignment")).to be false
end

it "uses exclusions passed in via the config hash" do
create_source_file("my_script", <<-EORUBY)
#!/usr/bin/env ruby

def method
unused = "x"

return false
end
EORUBY
config = { "exclude_paths" => ["my_script"] }
output = run_engine(config)

expect(includes_check?(output, "Lint/UselessAssignment")).to be false
end

it "layers config exclusions on top of the YAML config" do
create_source_file("foo.rb", <<-EORUBY)
def method
unused = "x"
return false
end
EORUBY
create_source_file("bar.rb", <<-EORUBY)
def method
unused = "x"
return false
end
EORUBY
create_source_file(
"rubocop.yml",
"AllCops:\n Exclude:\n - \"foo.rb\"\n"
)
config = { "config" => "rubocop.yml", "exclude_paths" => ["bar.rb"] }
output = run_engine(config)

expect(includes_check?(output, "Lint/UselessAssignment")).to be false
end

it "handles different locations properly" do
allow_any_instance_of(RuboCop::Cop::Team).to receive(:inspect_file).and_return(
[
Expand Down