Skip to content

Commit

Permalink
Merge pull request #27 from codeclimate/pb-fixes
Browse files Browse the repository at this point in the history
Minor fixes
  • Loading branch information
pbrisbin committed Feb 12, 2016
2 parents de0dde1 + 940a757 commit b1a5c51
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 34 deletions.
28 changes: 8 additions & 20 deletions lib/cc/engine/csslint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,18 @@ def results
@results ||= Nokogiri::XML(csslint_xml)
end

def build_files_with_exclusions(exclusions)
files = Dir.glob("**/*.css")
files.reject { |f| exclusions.include?(f) }
end

def build_files_with_inclusions(inclusions)
inclusions.map do |include_path|
if include_path =~ %r{/$}
Dir.glob("#{include_path}/**/*.css")
else
include_path if include_path =~ /\.css$/
end
end.flatten.compact
end

def csslint_xml
`csslint --format=checkstyle-xml #{files_to_inspect.join(" ")}`
`csslint --format=checkstyle-xml #{files_to_inspect.shelljoin}`
end

def files_to_inspect
if @engine_config["include_paths"]
build_files_with_inclusions(@engine_config["include_paths"])
else
build_files_with_exclusions(@engine_config["exclude_paths"] || [])
include_paths = @engine_config["include_paths"] || ["./"]
include_paths.each_with_object([]) do |path, out|
if path.end_with?("/")
out.concat(Dir.glob("#{path}**/*.css"))
elsif path.end_with?(".css")
out << path
end
end
end
end
Expand Down
15 changes: 1 addition & 14 deletions spec/cc/engine/csslint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,6 @@ module Engine
expect{ lint.run }.not_to output(/good\.css/).to_stdout
end

describe "with exclude_paths" do
let(:engine_config) { {"exclude_paths" => %w(excluded.css)} }

before do
create_source_file("not_excluded.css", "p { margin: 5px }")
create_source_file("excluded.css", id_selector_content)
end

it "excludes all matching paths" do
expect{ lint.run }.not_to \
output(/Don't use IDs in selectors./).to_stdout
end
end

describe "with include_paths" do
let(:engine_config) {
{"include_paths" => %w(included.css included_dir/ config.yml)}
Expand Down Expand Up @@ -79,6 +65,7 @@ module Engine
end

it "shouldn't call a top-level Dir.glob ever" do
allow(Dir).to receive(:glob).and_call_original
expect(Dir).not_to receive(:glob).with("**/*.css")
expect{ lint.run }.to \
output(/Don't use IDs in selectors./).to_stdout
Expand Down

0 comments on commit b1a5c51

Please sign in to comment.