Skip to content

Commit

Permalink
Revert "feat: Enable all rules by default, skip link change"
Browse files Browse the repository at this point in the history
This reverts commit fe72739.
  • Loading branch information
Marcy Sutton committed Dec 8, 2017
1 parent fe72739 commit 6cec9fc
Show file tree
Hide file tree
Showing 24 changed files with 200 additions and 57 deletions.
11 changes: 6 additions & 5 deletions doc/rule-descriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
| empty-heading | Ensures headings have discernible text | cat.name-role-value, best-practice | true |
| frame-title-unique | Ensures <iframe> and <frame> elements contain a unique title attribute | cat.text-alternatives, best-practice | true |
| frame-title | Ensures <iframe> and <frame> elements contain a non-empty title attribute | cat.text-alternatives, wcag2a, wcag241, section508, section508.22.i | true |
| heading-order | Ensures the order of headings is semantically correct | cat.semantics, best-practice | true |
| hidden-content | Informs users about hidden content. | experimental, review-item | true |
| heading-order | Ensures the order of headings is semantically correct | cat.semantics, best-practice | false |
| hidden-content | Informs users about hidden content. | experimental, review-item | false |
| href-no-hash | Ensures that href values are valid link references to promote only using anchors as links | cat.semantics, best-practice | false |
| html-has-lang | Ensures every HTML document has a lang attribute | cat.language, wcag2a, wcag311 | true |
| html-lang-valid | Ensures the lang attribute of the <html> element has a valid value | cat.language, wcag2a, wcag311 | true |
| image-alt | Ensures <img> elements have alternate text or a role of none or presentation | cat.text-alternatives, wcag2a, wcag111, section508, section508.22.a | true |
| image-redundant-alt | Ensure button and link text is not repeated as image alternative | cat.text-alternatives, best-practice | true |
| input-image-alt | Ensures <input type="image"> elements have alternate text | cat.text-alternatives, wcag2a, wcag111, section508, section508.22.a | true |
| label-title-only | Ensures that every form element is not solely labeled using the title or aria-describedby attributes | cat.forms, best-practice | true |
| label-title-only | Ensures that every form element is not solely labeled using the title or aria-describedby attributes | cat.forms, best-practice | false |
| label | Ensures every form element has a label | cat.forms, wcag2a, wcag332, wcag131, section508, section508.22.n | true |
| landmark-main-is-top-level | The main landmark should not be contained in another landmark | best-practice | true |
| landmark-one-main | Ensures a navigation point to the primary content of the page. If the page contains iframes, each iframe should contain either no main landmarks or just one. | best-practice | true |
Expand All @@ -46,10 +47,10 @@
| object-alt | Ensures <object> elements have alternate text | cat.text-alternatives, wcag2a, wcag111, section508, section508.22.a | true |
| p-as-heading | Ensure p elements are not used to style headings | cat.semantics, wcag2a, wcag131, experimental | true |
| radiogroup | Ensures related <input type="radio"> elements have a group and that the group designation is consistent | cat.forms, best-practice | true |
| region | Ensures all content is contained within a landmark region | cat.keyboard, best-practice | true |
| region | Ensures all content is contained within a landmark region | cat.keyboard, best-practice | false |
| scope-attr-valid | Ensures the scope attribute is used correctly on tables | cat.tables, best-practice | true |
| server-side-image-map | Ensures that server-side image maps are not used | cat.text-alternatives, wcag2a, wcag211, section508, section508.22.f | true |
| skip-link | Ensure all skip links have a focusable target | cat.keyboard, best-practice | true |
| skip-link | Ensures the first link on the page is a skip link | cat.keyboard, best-practice | false |
| tabindex | Ensures tabindex attribute values are not greater than 0 | cat.keyboard, best-practice | true |
| table-duplicate-name | Ensure that tables do not have the same summary and caption | cat.tables, best-practice | true |
| table-fake-caption | Ensure that tables with a caption use the <caption> element. | cat.tables, experimental, wcag2a, wcag131, section508, section508.22.g | true |
Expand Down
11 changes: 11 additions & 0 deletions lib/checks/navigation/href-no-hash.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"id": "href-no-hash",
"evaluate": "href-no-hash.js",
"metadata": {
"impact": "moderate",
"messages": {
"pass": "Anchor does not have an href value of #",
"fail": "Anchor has an href value of #"
}
}
}
1 change: 1 addition & 0 deletions lib/checks/navigation/skip-link-after.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
return [results[0]];
6 changes: 1 addition & 5 deletions lib/checks/navigation/skip-link.js
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
const target = axe.commons.dom.getElementByReference(node, 'href');
if (target) {
return axe.commons.dom.isVisible(target, true) || undefined;
}
return false;
return axe.commons.dom.isFocusable(axe.commons.dom.getElementByReference(node, 'href'));
6 changes: 3 additions & 3 deletions lib/checks/navigation/skip-link.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"id": "skip-link",
"evaluate": "skip-link.js",
"after": "skip-link-after.js",
"metadata": {
"impact": "moderate",
"messages": {
"pass": "Skip link target exists",
"incomplete": "Skip link target should become visible on activation",
"fail": "No skip link target"
"pass": "Valid skip link found",
"fail": "No valid skip link found"
}
}
}
1 change: 1 addition & 0 deletions lib/rules/empty-heading.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"id": "empty-heading",
"selector": "h1, h2, h3, h4, h5, h6, [role=\"heading\"]",
"enabled": true,
"tags": [
"cat.name-role-value",
"best-practice"
Expand Down
1 change: 1 addition & 0 deletions lib/rules/heading-order.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"id": "heading-order",
"selector": "h1,h2,h3,h4,h5,h6,[role=heading]",
"enabled": false,
"tags": [
"cat.semantics",
"best-practice"
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/hidden-content.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
"any": [
"hidden-content"
],
"none": []
"none": [],
"enabled": false
}
18 changes: 18 additions & 0 deletions lib/rules/href-no-hash.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"id": "href-no-hash",
"selector": "a[href]",
"enabled": false,
"tags": [
"cat.semantics",
"best-practice"
],
"metadata": {
"description": "Ensures that href values are valid link references to promote only using anchors as links",
"help": "Anchors must only be used as links with valid URLs or URL fragments"
},
"all": [],
"any": [
"href-no-hash"
],
"none": []
}
1 change: 1 addition & 0 deletions lib/rules/label-title-only.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"id": "label-title-only",
"selector": "input:not([type='hidden']):not([type='image']):not([type='button']):not([type='submit']):not([type='reset']), select, textarea",
"enabled": false,
"tags": [
"cat.forms",
"best-practice"
Expand Down
1 change: 1 addition & 0 deletions lib/rules/region.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"id": "region",
"selector": "html",
"pageLevel": true,
"enabled": false,
"tags": [
"cat.keyboard",
"best-practice"
Expand Down
1 change: 1 addition & 0 deletions lib/rules/scope-attr-valid.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"id": "scope-attr-valid",
"selector": "td[scope], th[scope]",
"enabled": true,
"tags": [
"cat.tables",
"best-practice"
Expand Down
2 changes: 0 additions & 2 deletions lib/rules/skip-link-matches.js

This file was deleted.

7 changes: 4 additions & 3 deletions lib/rules/skip-link.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"id": "skip-link",
"selector": "a[href]",
"matches": "skip-link-matches.js",
"pageLevel": true,
"enabled": false,
"tags": [
"cat.keyboard",
"best-practice"
],
"metadata": {
"description": "Ensure all skip links have a focusable target",
"help": "The skip-link target should exist and be focusable"
"description": "Ensures the first link on the page is a skip link",
"help": "The page should have a skip link as its first link"
},
"all": [],
"any": [
Expand Down
27 changes: 27 additions & 0 deletions test/checks/navigation/href-no-hash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
describe('href-no-hash', function () {
'use strict';

var fixture = document.getElementById('fixture');

afterEach(function () {
fixture.innerHTML = '';
});

it('should return false if the href points to only hash', function () {
fixture.innerHTML = '<a href="#">Click Here</a>';
var node = fixture.querySelector('a');
assert.isFalse(checks['href-no-hash'].evaluate(node));
});

it('should return true if the href points to hash plus id', function () {
fixture.innerHTML = '<a href="#test">Click Here</a>';
var node = fixture.querySelector('a');
assert.isTrue(checks['href-no-hash'].evaluate(node));
});

it('should return true if the href is empty', function () {
fixture.innerHTML = '<a href="">Click Here</a>';
var node = fixture.querySelector('a');
assert.isTrue(checks['href-no-hash'].evaluate(node));
});
});
27 changes: 9 additions & 18 deletions test/checks/navigation/skip-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,20 @@ describe('skip-link', function () {
assert.isFalse(checks['skip-link'].evaluate(node));
});

it('should return true if the href points to an element with an ID', function () {
fixture.innerHTML = '<a href="#target">Click Here</a><h1 id="target">Introduction</h1>';
it('should return false if the href points to a non-focusable element', function () {
fixture.innerHTML = '<a href="#mainheader">Click Here</a><h1 id="mainheader">Introduction</h1>';
var node = fixture.querySelector('a');
assert.isTrue(checks['skip-link'].evaluate(node));
});

it('should return true if the href points to an element with an name', function () {
fixture.innerHTML = '<a href="#target">Click Here</a><a name="target"></a>';
var node = fixture.querySelector('a');
assert.isTrue(checks['skip-link'].evaluate(node));
assert.isFalse(checks['skip-link'].evaluate(node));
});

it('should return undefined if the target has display:none', function () {
fixture.innerHTML = '<a href="#target">Click Here</a>' +
'<h1 id="target" style="display:none">Introduction</h1>';
var node = fixture.querySelector('a');
assert.isUndefined(checks['skip-link'].evaluate(node));
it('should return first result of an array', function () {
var results = [1, 2, 3];
assert.equal(checks['skip-link'].after(results), 1);
});

it('should return undefined if the target has aria-hidden=true', function () {
fixture.innerHTML = '<a href="#target">Click Here</a>' +
'<h1 id="target" aria-hidden="true">Introduction</h1>';
it('should return true if the href points to a focusable element', function () {
fixture.innerHTML = '<a href="#mainheader">Click Here</a><h1 id="mainheader" tabindex="0">Introduction</h1>';
var node = fixture.querySelector('a');
assert.isUndefined(checks['skip-link'].evaluate(node));
assert.isTrue(checks['skip-link'].evaluate(node));
});
});
23 changes: 23 additions & 0 deletions test/integration/full/skip-link/skip-link-fail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Skip-Link Test</title>
<link rel="stylesheet" type="text/css" href="/node_modules/mocha/mocha.css" />
<script src="/node_modules/mocha/mocha.js"></script>
<script src="/node_modules/chai/chai.js"></script>
<script src="/axe.js"></script>
<script>
mocha.setup({
timeout: 10000,
ui: 'bdd'
});
var assert = chai.assert;
</script>
</head>
<body>
<p><a href="http://www.google.com" id="firstlink">This document is going to fail the skip-link test.</a></p>
<div id="mocha"></div>
<script src="skip-link-fail.js"></script>
<script src="/test/integration/adapter.js"></script>
</body>
</html>
27 changes: 27 additions & 0 deletions test/integration/full/skip-link/skip-link-fail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
describe('skip link fail test', function () {
'use strict';
var results;
before(function (done) {
axe.run({ runOnly: { type: 'rule', values: ['skip-link'] } }, function (err, r) {
assert.isNull(err);
results = r;
done();
});
});

describe('violations', function () {
it('should find one', function () {
assert.lengthOf(results.violations[0].nodes, 1);
});

it('should find html', function () {
assert.deepEqual(results.violations[0].nodes[0].target, ['#firstlink']);
});
});

describe('passes', function () {
it('should find none', function () {
assert.lengthOf(results.passes, 0);
});
});
});
24 changes: 24 additions & 0 deletions test/integration/full/skip-link/skip-link-pass.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Skip-Link Test</title>
<link rel="stylesheet" type="text/css" href="/node_modules/mocha/mocha.css" />
<script src="/node_modules/mocha/mocha.js"></script>
<script src="/node_modules/chai/chai.js"></script>
<script src="/axe.js"></script>
<script>
mocha.setup({
timeout: 10000,
ui: 'bdd'
});
var assert = chai.assert;
</script>
</head>
<body>
<p><a href="#main" id="firstlink">This document is going to pass the skip-link test.</a></p>
<h1 tabindex="0" id="main">Focusable header</h1>
<div id="mocha"></div>
<script src="skip-link-pass.js"></script>
<script src="/test/integration/adapter.js"></script>
</body>
</html>
27 changes: 27 additions & 0 deletions test/integration/full/skip-link/skip-link-pass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
describe('skip link pass test', function () {
'use strict';
var results;
before(function (done) {
axe.run({ runOnly: { type: 'rule', values: ['skip-link'] } }, function (err, r) {
assert.isNull(err);
results = r;
done();
});
});

describe('passes', function () {
it('should find one', function () {
assert.lengthOf(results.passes[0].nodes, 1);
});

it('should find html', function () {
assert.deepEqual(results.passes[0].nodes[0].target, ['#firstlink']);
});
});

describe('violations', function () {
it('should find none', function () {
assert.lengthOf(results.violations, 0);
});
});
});
6 changes: 6 additions & 0 deletions test/integration/rules/href-no-hash/href-no-hash.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<a href="#" id="fail1">My anchor</a>

<a href="#test" id="pass1">My anchor</a>

<a href="" id="pass2">My anchor</a>

6 changes: 6 additions & 0 deletions test/integration/rules/href-no-hash/href-no-hash.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"description": "href-no-hash test",
"rule": "href-no-hash",
"violations": [["#fail1"]],
"passes": [["#pass1"], ["#pass2"]]
}
14 changes: 0 additions & 14 deletions test/integration/rules/skip-link/skip-link.html

This file was deleted.

6 changes: 0 additions & 6 deletions test/integration/rules/skip-link/skip-link.json

This file was deleted.

0 comments on commit 6cec9fc

Please sign in to comment.