File tree Expand file tree Collapse file tree 2 files changed +60
-5
lines changed Expand file tree Collapse file tree 2 files changed +60
-5
lines changed Original file line number Diff line number Diff line change @@ -48,14 +48,31 @@ def results
48
48
@results ||= Nokogiri ::XML ( csslint_xml )
49
49
end
50
50
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
+
51
66
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 ( " " ) } `
55
68
end
56
69
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
59
76
end
60
77
end
61
78
end
Original file line number Diff line number Diff line change @@ -35,6 +35,44 @@ module Engine
35
35
output ( /Don't use IDs in selectors./ ) . to_stdout
36
36
end
37
37
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
38
76
end
39
77
40
78
def create_source_file ( path , content )
You can’t perform that action at this time.
0 commit comments