Skip to content

Commit

Permalink
Merge pull request #277 from gjtorikian/external-only
Browse files Browse the repository at this point in the history
Add option to *just* check for external issues
  • Loading branch information
gjtorikian committed Dec 5, 2015
2 parents 4842e22 + de725ba commit fce9417
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 14 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ The `HTML::Proofer` constructor takes an optional hash of additional options:
| `enforce_https` | Fails a link if it's not marked as `https`. | `false` |
| `error_sort` | Defines the sort order for error output. Can be `:path`, `:desc`, or `:status`. | `:path`
| `ext` | The extension of your HTML files including the dot. | `.html`
| `external_only` | Only checks problems with external references. | `false`
| `file_ignore` | An array of Strings or RegExps containing file paths that are safe to ignore. | `[]` |
| `href_ignore` | An array of Strings or RegExps containing `href`s that are safe to ignore. Note that non-HTTP(S) URIs are always ignored. **Will be renamed in a future release.** | `[]` |
| `href_swap` | A hash containing key-value pairs of `RegExp => String`. It transforms links that match `RegExp` into `String` via `gsub`. **Will be renamed in a future release.** | `{}` |
Expand Down
1 change: 1 addition & 0 deletions bin/htmlproof
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Mercenary.program(:htmlproof) do |p|
p.option 'error_sort', '--error-sort SORT', 'Defines the sort order for error output. Can be `:path`, `:desc`, or `:status` (default: `path`).'
p.option 'enforce_https', '--enforce-https', 'Fails a link if it\'s not marked as `https` (default: `false`).'
p.option 'ext', '--ext EXT', String, 'The extension of your HTML files including the dot. (default: `.html`)'
p.option 'external_only', '--external_only', 'Only checks problems with external references'
p.option 'file_ignore', '--file-ignore file1,[file2,...]', Array, 'A comma-separated list of Strings or RegExps containing file paths that are safe to ignore'
p.option 'href_ignore', '--href-ignore link1,[link2,...]', Array, 'A comma-separated list of Strings or RegExps containing `href`s that are safe to ignore. Note that non-HTTP(S) URIs are always ignored. **Will be renamed in a future release.**'
p.option 'href_swap', '--href-swap re:string,[re:string,...]', Array, 'A comma-separated list containing key-value pairs of `RegExp => String`. It transforms links that match `RegExp` into `String` via `gsub`. **Will be renamed in a future release.**'
Expand Down
10 changes: 9 additions & 1 deletion lib/html/proofer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,15 @@ def check_directory_of_files
@failed_tests.concat(item[:failed_tests])
end

validate_urls unless @options[:disable_external]
# TODO: lazy. if we're checking only external links,
# we'll just trash all the failed tests. really, we should
# just not run those other checks at all.
if @options[:external_only]
@failed_tests = []
validate_urls
elsif !@options[:disable_external]
validate_urls
end

count = files.length
file_text = pluralize(count, 'file', 'files')
Expand Down
27 changes: 14 additions & 13 deletions lib/html/proofer/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@ module Configuration
require_relative 'version'

PROOFER_DEFAULTS = {
:ext => '.html',
:check_favicon => false,
:href_swap => [],
:href_ignore => [],
:allow_hash_href => false,
:file_ignore => [],
:url_ignore => [],
:check_external_hash => false,
:alt_ignore => [],
:check_external_hash => false,
:check_favicon => false,
:check_html => false,
:checks_to_ignore => [],
:directory_index_file => 'index.html',
:disable_external => false,
:empty_alt_ignore => false,
:enforce_https => false,
:disable_external => false,
:verbose => false,
:only_4xx => false,
:directory_index_file => 'index.html',
:check_html => false,
:error_sort => :path,
:checks_to_ignore => []
:ext => '.html',
:external_only => false,
:file_ignore => [],
:href_ignore => [],
:href_swap => [],
:only_4xx => false,
:url_ignore => [],
:verbose => false
}

TYPHOEUS_DEFAULTS = {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions spec/html/proofer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,20 @@
expect(proofer.checks.length).to eq 3
end
end

describe 'external only' do
it 'knows how to ignore non-external link failures' do
options = { :external_only => true }
missingAltFilepath = "#{FIXTURES_DIR}/images/missingImageAlt.html"
proofer = run_proofer(missingAltFilepath, options)
expect(proofer.failed_tests).to eq []
end

it 'still reports external link failures' do
options = { :external_only => true }
external = "#{FIXTURES_DIR}/links/brokenLinkExternal.html"
proofer = run_proofer(external, options)
expect(proofer.failed_tests.length).to eq 1
end
end
end

0 comments on commit fce9417

Please sign in to comment.