From 0e01d960e8c9f5bf87455d2abebdcb65e607ee22 Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" Date: Tue, 1 Nov 2022 16:45:26 -0300 Subject: [PATCH 1/3] Accept regexp values for ignore-files via CLI --- lib/html_proofer/configuration.rb | 12 +++++++++++- lib/html_proofer/runner.rb | 10 ++++++++-- spec/html-proofer/command_spec.rb | 8 +++++++- spec/spec_helper.rb | 5 +++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/lib/html_proofer/configuration.rb b/lib/html_proofer/configuration.rb index 62f00d6e..f5a4edfc 100644 --- a/lib/html_proofer/configuration.rb +++ b/lib/html_proofer/configuration.rb @@ -134,7 +134,17 @@ def parse_cli_options(args) section(opts, "Ignore Configuration") do set_option(opts, "--ignore-files [FILE1,FILE2,...]") do |long_opt_symbol, list| - @options[long_opt_symbol] = list.nil? ? [] : list.split(",") + @options[long_opt_symbol] = if list.nil? + [] + else + list.split(",").map.each do |l| + if l.start_with?("/") && l.end_with?("/") + Regexp.new(l[1...-1]) + else + l + end + end + end end set_option(opts, "--[no-]ignore-empty-alt") do |long_opt_symbol, arg| diff --git a/lib/html_proofer/runner.rb b/lib/html_proofer/runner.rb index 47e2510c..ba6719a8 100644 --- a/lib/html_proofer/runner.rb +++ b/lib/html_proofer/runner.rb @@ -166,8 +166,14 @@ def files def ignore_file?(file) @options[:ignore_files].each do |pattern| - return true if pattern.is_a?(String) && pattern == file - return true if pattern.is_a?(Regexp) && pattern =~ file + if pattern.is_a?(String) && pattern == file + @logger.log(:debug, "Ignoring #{file} because it matches #{pattern}") + return true + end + next unless pattern.is_a?(Regexp) && pattern.match(file) + + @logger.log(:debug, "Ignoring #{file} because it matches regexp #{pattern}") + return true end false diff --git a/spec/html-proofer/command_spec.rb b/spec/html-proofer/command_spec.rb index a490fa53..bc298c5e 100644 --- a/spec/html-proofer/command_spec.rb +++ b/spec/html-proofer/command_spec.rb @@ -134,12 +134,18 @@ expect(output).to(match("failure")) end - it "works with ignore-files" do + it "works with ignore-files (string)" do external = File.join(FIXTURES_DIR, "links", "broken_hash_internal.html") output = make_bin("--ignore-files #{external} #{external}") expect(output).to(match("successfully")) end + it "works with ignore-files (regexp)" do + external = File.join(FIXTURES_DIR, "links", "broken_hash_internal.html") + output = make_bin("--ignore-files /_hash_/ #{external}") + expect(output).to(match("successfully")) + end + it "works with ignore-missing-alt" do broken = File.join(FIXTURES_DIR, "images", "missing_image_alt.html") output = make_bin("--ignore-missing-alt #{broken}") diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9007a14c..aa8a43ff 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -70,6 +70,7 @@ def capture_proofer_http(item, type, opts = {}) end def make_bin(args) + ap("#{RbConfig.ruby} exe/htmlproofer #{args}") if debug? stdout, stderr = Open3.capture3("#{RbConfig.ruby} exe/htmlproofer #{args}") "#{stdout}\n#{stderr}".encode("UTF-8", invalid: :replace, undef: :replace) end @@ -84,6 +85,10 @@ def make_cassette_name(file, opts) filename end +def debug? + ENV.fetch("DEBUG", false) +end + def ci? ENV.fetch("CI", false) end From e52aa43f7b9fd7a2150fb0ffaee12bc2325fd8e4 Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" Date: Tue, 1 Nov 2022 16:46:14 -0300 Subject: [PATCH 2/3] lint --- lib/html_proofer/configuration.rb | 2 +- spec/html-proofer/command_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/html_proofer/configuration.rb b/lib/html_proofer/configuration.rb index f5a4edfc..ce986322 100644 --- a/lib/html_proofer/configuration.rb +++ b/lib/html_proofer/configuration.rb @@ -295,7 +295,7 @@ module ConfigurationHelp check_internal_hash: ["Checks whether internal hashes exist (even if the webpage exists) (default: `true`)."], check_sri: ["Check that `` and `