From b43a484b7554bbf8563a188bb141843467caec24 Mon Sep 17 00:00:00 2001 From: patrick brisbin Date: Fri, 12 Feb 2016 09:28:12 -0500 Subject: [PATCH 1/2] Remove support for exclude_paths Refactor #files_to_inspect a little in the course of doing so. --- lib/cc/engine/csslint.rb | 26 +++++++------------------- spec/cc/engine/csslint_spec.rb | 15 +-------------- 2 files changed, 8 insertions(+), 33 deletions(-) diff --git a/lib/cc/engine/csslint.rb b/lib/cc/engine/csslint.rb index 2b2d9fe..0881d64 100644 --- a/lib/cc/engine/csslint.rb +++ b/lib/cc/engine/csslint.rb @@ -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(" ")}` 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 diff --git a/spec/cc/engine/csslint_spec.rb b/spec/cc/engine/csslint_spec.rb index ec5e0a8..356848c 100644 --- a/spec/cc/engine/csslint_spec.rb +++ b/spec/cc/engine/csslint_spec.rb @@ -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)} @@ -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 From 940a757b34a1b4d08367bc92fd9318445d1da009 Mon Sep 17 00:00:00 2001 From: patrick brisbin Date: Fri, 12 Feb 2016 09:29:35 -0500 Subject: [PATCH 2/2] Use shelljoin Ensures any file arguments with spaces are correctly handled. --- lib/cc/engine/csslint.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cc/engine/csslint.rb b/lib/cc/engine/csslint.rb index 0881d64..cbbb3dd 100644 --- a/lib/cc/engine/csslint.rb +++ b/lib/cc/engine/csslint.rb @@ -62,7 +62,7 @@ def results 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