Skip to content

Commit

Permalink
Merge pull request #53 from codeclimate/will/drop-exclude-paths
Browse files Browse the repository at this point in the history
Drop support for "exclude_paths" in engine config
  • Loading branch information
wfleming committed Feb 16, 2016
2 parents e27bb9f + 4678d48 commit 8181759
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 65 deletions.
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

0 comments on commit 8181759

Please sign in to comment.