Skip to content

Minor fixes #27

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 2 commits into from
Feb 12, 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: 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