Skip to content

Commit

Permalink
Add IgnoreEmptyHref option
Browse files Browse the repository at this point in the history
  • Loading branch information
martinbaillie committed Jun 22, 2019
1 parent f8a0ead commit 083b3bb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -140,6 +140,7 @@ htmltest uses a YAML configuration file. Put `.htmltest.yml` in the same directo
| `IgnoreURLs` | Array of regexs of URLs to ignore. | empty |
| `IgnoreDirs` | Array of regexs of directories to ignore when scanning for HTML files. | empty |
| `IgnoreInternalEmptyHash` | When true prevents raising an error for links with `href="#"`. | `false` |
| `IgnoreEmptyHref` | When true prevents raising an error for links with `href=""`. | `false` |
| `IgnoreCanonicalBrokenLinks` | When true produces a warning, rather than an error, for broken canonical links. When testing a site which isn't live yet or before publishing a new page canonical links will fail. | `true` |
| `IgnoreAltMissing` | Turns off image alt attribute checking. | `false` |
| `IgnoreDirectoryMissingTrailingSlash` | Turns off errors for links to directories without a trailing slash. | `false` |
Expand Down
12 changes: 7 additions & 5 deletions htmltest/check-link.go
Expand Up @@ -54,11 +54,13 @@ func (hT *HTMLTest) checkLink(document *htmldoc.Document, node *html.Node) {

// Blank href
if attrs["href"] == "" {
hT.issueStore.AddIssue(issues.Issue{
Level: issues.LevelError,
Message: "href blank",
Reference: ref,
})
if !hT.opts.IgnoreEmptyHref {
hT.issueStore.AddIssue(issues.Issue{
Level: issues.LevelError,
Message: "href blank",
Reference: ref,
})
}
return
}

Expand Down
7 changes: 7 additions & 0 deletions htmltest/check-link_test.go
Expand Up @@ -467,6 +467,13 @@ func TestLinkHrefBlank(t *testing.T) {
tExpectIssue(t, hT, "href blank", 1)
}

func TestLinkHrefBlankIgnore(t *testing.T) {
// works for empty href within link elements when ignoring
hT := tTestFileOpts("fixtures/links/head_link_href_empty.html",
map[string]interface{}{"IgnoreEmptyHref": true})
tExpectIssueCount(t, hT, 0)
}

func TestLinkHrefAbsent(t *testing.T) {
// fails for absent href within link elements
hT := tTestFile("fixtures/links/head_link_href_absent.html")
Expand Down
2 changes: 2 additions & 0 deletions htmltest/options.go
Expand Up @@ -41,6 +41,7 @@ type Options struct {
IgnoreDirs []interface{}

IgnoreInternalEmptyHash bool
IgnoreEmptyHref bool
IgnoreCanonicalBrokenLinks bool
IgnoreAltMissing bool
IgnoreDirectoryMissingTrailingSlash bool
Expand Down Expand Up @@ -103,6 +104,7 @@ func DefaultOptions() map[string]interface{} {
"IgnoreDirs": []interface{}{},

"IgnoreInternalEmptyHash": false,
"IgnoreEmptyHref": false,
"IgnoreCanonicalBrokenLinks": true,
"IgnoreAltMissing": false,
"IgnoreDirectoryMissingTrailingSlash": false,
Expand Down

0 comments on commit 083b3bb

Please sign in to comment.