Skip to content

Commit

Permalink
fix: Separate Level AAA rules from A and best-practices (#3191)
Browse files Browse the repository at this point in the history
* fix: Separate Level AAA rules from A and best-practices

* Don't log use of wcag21aaa as a tag

* address comments
  • Loading branch information
WilcoFiers authored and straker committed Oct 18, 2021
1 parent ab636ef commit 7e6e6da
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 39 deletions.
8 changes: 8 additions & 0 deletions build/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ function buildRules(grunt, options, commons, callback) {
'Rules that do not necessarily conform to WCAG success criterion but are industry accepted practices that improve the user experience.',
rules: []
},
wcag2aaa: {
title: 'WCAG 2.0 and 2.1 level AAA rules',
intro:
'Rules that check for conformance to WCAG AAA success criteria that can be fully automated.',
rules: []
},
experimental: {
title: 'Experimental Rules',
intro:
Expand Down Expand Up @@ -335,6 +341,8 @@ function buildRules(grunt, options, commons, callback) {
rules = descriptions.deprecated.rules;
} else if (rule.tags.includes('experimental')) {
rules = descriptions.experimental.rules;
} else if (rule.tags.find(tag => tag.includes('aaa'))) {
rules = descriptions.wcag2aaa.rules;
} else if (rule.tags.includes('best-practice')) {
rules = descriptions.bestPractice.rules;
} else if (rule.tags.find(tag => tag.startsWith('wcag2a'))) {
Expand Down
2 changes: 2 additions & 0 deletions doc/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ The `experimental`, `ACT` and `section508` tags are only added to some rules. Ea
| ---------------- | ---------------------------------------------------- |
| `wcag2a` | WCAG 2.0 Level A |
| `wcag2aa` | WCAG 2.0 Level AA |
| `wcag2aaa` | WCAG 2.0 Level AAA |
| `wcag21a` | WCAG 2.1 Level A |
| `wcag21aa` | WCAG 2.1 Level AA |
| `wcag21aaa` | WCAG 2.1 Level AAA |
| `best-practice` | Common accessibility best practices |
| `wcag***` | WCAG success criterion e.g. wcag111 maps to SC 1.1.1 |
| `ACT` | W3C approved Accessibility Conformance Testing rules |
Expand Down
74 changes: 41 additions & 33 deletions doc/rule-descriptions.md

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions lib/core/base/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
performanceTimer
} from '../utils';
import doT from '@deque/dot';
import log from '../log';
import constants from '../constants';

const dotRegex = /\{\{.+?\}\}/g;
Expand Down Expand Up @@ -592,9 +591,13 @@ class Audit {
// Validate 'tags' (e.g. anything not 'rule')
} else if (['tag', 'tags', undefined].includes(only.type)) {
only.type = 'tag';
const unmatchedTags = only.values.filter(tag => !tags.includes(tag));
if (unmatchedTags.length !== 0) {
log('Could not find tags `' + unmatchedTags.join('`, `') + '`');

const unmatchedTags = only.values.filter(tag => (
!tags.includes(tag) &&
!/wcag2[1-3]a{1,3}/.test(tag)
));
if (unmatchedTags.length !== 0) {
axe.log('Could not find tags `' + unmatchedTags.join('`, `') + '`');
}
} else {
throw new Error(`Unknown runOnly type '${only.type}'`);
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/identical-links-same-purpose.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"selector": "a[href], area[href], [role=\"link\"]",
"excludeHidden": false,
"matches": "identical-links-same-purpose-matches",
"tags": ["cat.semantics", "wcag2aaa", "wcag249", "best-practice"],
"tags": ["cat.semantics", "wcag2aaa", "wcag249"],
"actIds": ["b20e66", "fd3a94"],
"metadata": {
"description": "Ensure that links with the same accessible name serve a similar purpose",
Expand Down
1 change: 0 additions & 1 deletion lib/rules/meta-refresh.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"tags": [
"cat.time-and-media",
"wcag2a",
"wcag2aaa",
"wcag221",
"wcag224",
"wcag325"
Expand Down
50 changes: 50 additions & 0 deletions test/core/base/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,14 @@ describe('Audit', function() {
});

describe('Audit#normalizeOptions', function() {
var axeLog;
beforeEach(function () {
axeLog = axe.log;
});
afterEach(function () {
axe.log = axeLog;
});

it('returns the options object when it is valid', function() {
var opt = {
runOnly: {
Expand Down Expand Up @@ -1440,5 +1448,47 @@ describe('Audit', function() {
});
});
});

it('logs an issue when a tag is unknown', function () {
var message = '';
axe.log = function (m) {
message = m;
};
a.normalizeOptions({
runOnly: {
type: 'tags',
values: ['unknwon-tag']
}
});
assert.include(message, 'Could not find tags');
});

it('logs no issues for unknown WCAG level tags', function () {
var message = '';
axe.log = function (m) {
message = m;
};
a.normalizeOptions({
runOnly: {
type: 'tags',
values: ['wcag23aaa']
}
});
assert.isEmpty(message);
});

it('logs an issue when a tag is unknown, together with a wcag level tag', function () {
var message = '';
axe.log = function (m) {
message = m;
};
a.normalizeOptions({
runOnly: {
type: 'tags',
values: ['wcag23aaa', 'unknwon-tag']
}
});
assert.include(message, 'Could not find tags');
});
});
});

0 comments on commit 7e6e6da

Please sign in to comment.