Skip to content

Commit

Permalink
docs: show which rules can return failures and incomplete in rule-des…
Browse files Browse the repository at this point in the history
…criptions.md (#1895)

* chore: show which rules can return failures and incomplete in rule-descriptions.md

* Empty commit to trigger CLA thing
  • Loading branch information
straker authored Nov 13, 2019
1 parent e217211 commit ac70a16
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 103 deletions.
72 changes: 56 additions & 16 deletions build/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var buildManual = require('./build-manual');
var entities = new (require('html-entities')).AllHtmlEntities();

var descriptionHeaders =
'| Rule ID | Description | Impact | Tags | Enabled by default |\n| :------- | :------- | :------- | :------- | :------- |\n';
'| Rule ID | Description | Impact | Tags | Enabled by default | Failures | Needs Review |\n| :------- | :------- | :------- | :------- | :------- | :------- | :------- |\n';

dot.templateSettings.strip = false;

Expand Down Expand Up @@ -153,6 +153,17 @@ function buildRules(grunt, options, commons, callback) {
});
}

function traverseChecks(checkCollection, predicate, startValue) {
return checkCollection.reduce(function(out, check) {
var id = typeof check === 'string' ? check : check.id;
var definition = clone(findCheck(checks, id));
if (!definition) {
grunt.log.error('check ' + id + ' not found');
}
return predicate(definition, out);
}, startValue);
}

function parseImpactForRule(rule) {
function capitalize(s) {
return s.charAt(0).toUpperCase() + s.slice(1);
Expand All @@ -164,23 +175,16 @@ function buildRules(grunt, options, commons, callback) {
});
}

function getImpactScores(checkCollection) {
return checkCollection.reduce(function(out, check) {
var id = typeof check === 'string' ? check : check.id;
var definition = clone(findCheck(checks, id));
if (!definition) {
grunt.log.error('check ' + id + ' not found');
}
if (definition && definition.metadata && definition.metadata.impact) {
var impactScore = axeImpact.indexOf(definition.metadata.impact);
out.push(impactScore);
}
return out;
}, []);
function getImpactScores(definition, out) {
if (definition && definition.metadata && definition.metadata.impact) {
var impactScore = axeImpact.indexOf(definition.metadata.impact);
out.push(impactScore);
}
return out;
}

function getScore(checkCollection, onlyHighestScore) {
var scores = getImpactScores(checkCollection);
var scores = traverseChecks(checkCollection, getImpactScores, []);
if (scores && scores.length) {
return onlyHighestScore
? [Math.max.apply(null, scores)]
Expand All @@ -205,20 +209,56 @@ function buildRules(grunt, options, commons, callback) {
}, '');
}

function parseFailureForRule(rule) {
function hasFailure(definition, out) {
if (definition && definition.metadata && definition.metadata.impact) {
out = out || !!definition.metadata.messages.fail;
}
return out;
}

return (
traverseChecks(rule.any, hasFailure, false) ||
traverseChecks(rule.all, hasFailure, false) ||
traverseChecks(rule.none, hasFailure, false)
);
}

function parseIncompleteForRule(rule) {
function hasIncomplete(definition, out) {
if (definition && definition.metadata && definition.metadata.impact) {
out = out || !!definition.metadata.messages.incomplete;
}
return out;
}

return (
traverseChecks(rule.any, hasIncomplete, false) ||
traverseChecks(rule.all, hasIncomplete, false) ||
traverseChecks(rule.none, hasIncomplete, false)
);
}

rules.map(function(rule) {
var impact = parseImpactForRule(rule);
var canFail = parseFailureForRule(rule);
var canIncomplete = parseIncompleteForRule(rule);

rule.any = parseChecks(rule.any);
rule.all = parseChecks(rule.all);
rule.none = parseChecks(rule.none);
if (rule.metadata && !metadata.rules[rule.id]) {
metadata.rules[rule.id] = parseMetaData(rule, 'rules'); // Translate rules
}

descriptions.push([
rule.id,
entities.encode(rule.metadata.description),
impact,
rule.tags.join(', '),
rule.enabled === false ? false : true
rule.enabled === false ? false : true,
canFail,
canIncomplete
]);
if (tags.length) {
rule.enabled = !!rule.tags.filter(function(t) {
Expand Down
Loading

0 comments on commit ac70a16

Please sign in to comment.