Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0ec86aa

Browse files
committed
Support either include_paths or exclude_paths.
1 parent bcc620f commit 0ec86aa

File tree

2 files changed

+60
-5
lines changed

2 files changed

+60
-5
lines changed

lib/cc/engine/csslint.rb

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,31 @@ def results
4848
@results ||= Nokogiri::XML(csslint_xml)
4949
end
5050

51+
def build_files_with_exclusions(exclusions)
52+
files = Dir.glob("**/*.css")
53+
files.reject { |f| exclusions.include?(f) }
54+
end
55+
56+
def build_files_with_inclusions(inclusions)
57+
inclusions.map do |include_path|
58+
if include_path =~ %r{/$}
59+
Dir.glob("#{include_path}/**/*.css")
60+
else
61+
include_path
62+
end
63+
end.flatten
64+
end
65+
5166
def csslint_xml
52-
exclusions = @engine_config['exclude_paths'] || []
53-
final_files = files.reject { |f| exclusions.include?(f) }
54-
`csslint --format=checkstyle-xml #{final_files.join(" ")}`
67+
`csslint --format=checkstyle-xml #{files_to_inspect.join(" ")}`
5568
end
5669

57-
def files
58-
Dir.glob("**/*.css")
70+
def files_to_inspect
71+
if includes = @engine_config["include_paths"]
72+
build_files_with_inclusions(includes)
73+
else
74+
build_files_with_exclusions(@engine_config["exclude_paths"] || [])
75+
end
5976
end
6077
end
6178
end

spec/cc/engine/csslint_spec.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,44 @@ module Engine
3535
output(/Don't use IDs in selectors./).to_stdout
3636
end
3737
end
38+
39+
describe "with include_paths" do
40+
let(:engine_config) {
41+
{"include_paths" => %w(included.css included_dir/)}
42+
}
43+
44+
before do
45+
create_source_file("included.css", id_selector_content)
46+
create_source_file(
47+
"included_dir/file.css", "p { color: blue !important; }"
48+
)
49+
create_source_file(
50+
"included_dir/sub/sub/subdir/file.css", "img { }"
51+
)
52+
create_source_file("not_included.css", "a { outline: none; }")
53+
end
54+
55+
it "includes all mentioned files" do
56+
expect{ lint.run }.to \
57+
output(/Don't use IDs in selectors./).to_stdout
58+
end
59+
60+
it "expands directories" do
61+
expect{ lint.run }.to output(/Use of !important/).to_stdout
62+
expect{ lint.run }.to output(/Rule is empty/).to_stdout
63+
end
64+
65+
it "excludes any unmentioned files" do
66+
expect{ lint.run }.not_to \
67+
output(/Outlines should only be modified using :focus/).to_stdout
68+
end
69+
70+
it "shouldn't call a top-level Dir.glob ever" do
71+
expect(Dir).not_to receive(:glob).with("**/*.css")
72+
expect{ lint.run }.to \
73+
output(/Don't use IDs in selectors./).to_stdout
74+
end
75+
end
3876
end
3977

4078
def create_source_file(path, content)

0 commit comments

Comments
 (0)