Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Separate Level AAA rules from A and best-practices #3191

Merged
merged 4 commits into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
WilcoFiers marked this conversation as resolved.
Show resolved Hide resolved
| `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');
});
});
});