UNPKG

axe-sarif-converter

Version:

Convert axe-core accessibility scan results to the SARIF format

82 lines (81 loc) 4.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ResultToRuleConverter = void 0; var wcag_taxonomy_provider_1 = require("./wcag-taxonomy-provider"); var ResultToRuleConverter = /** @class */ (function () { function ResultToRuleConverter(rulesDictionary) { this.ruleIdsToRuleIndices = {}; this.rulesDictionary = {}; this.sortedRuleIds = []; this.rulesDictionary = rulesDictionary; this.sortRuleIds(); this.indexRuleIds(); } ResultToRuleConverter.fromRawResults = function (results, axeTags, wcagTagsToTaxaIndices) { var rulesDictionary = {}; ResultToRuleConverter.convertResultsToRules(results, axeTags, wcagTagsToTaxaIndices, rulesDictionary); return new ResultToRuleConverter(rulesDictionary); }; ResultToRuleConverter.fromV2Results = function (results, axeTags, wcagTagsToTaxaIndices) { var rulesDictionary = {}; ResultToRuleConverter.convertV2ResultsToRules(results, axeTags, wcagTagsToTaxaIndices, rulesDictionary); return new ResultToRuleConverter(rulesDictionary); }; ResultToRuleConverter.prototype.getRulePropertiesFromResults = function () { var _this = this; return this.sortedRuleIds.map(function (ruleId) { return _this.rulesDictionary[ruleId]; }); }; ResultToRuleConverter.prototype.getRuleIdsToRuleIndices = function () { return this.ruleIdsToRuleIndices; }; ResultToRuleConverter.prototype.sortRuleIds = function () { this.sortedRuleIds = Object.keys(this.rulesDictionary).sort(); }; ResultToRuleConverter.prototype.indexRuleIds = function () { for (var i = 0; i < this.sortedRuleIds.length; i++) { this.ruleIdsToRuleIndices[this.sortedRuleIds[i]] = i; } }; ResultToRuleConverter.convertV2ResultsToRules = function (results, axeTags, wcagTagsToTaxaIndices, rulesDictionary) { ResultToRuleConverter.convertResultsToRules(results.violations, axeTags, wcagTagsToTaxaIndices, rulesDictionary); ResultToRuleConverter.convertResultsToRules(results.passes, axeTags, wcagTagsToTaxaIndices, rulesDictionary); ResultToRuleConverter.convertResultsToRules(results.inapplicable, axeTags, wcagTagsToTaxaIndices, rulesDictionary); ResultToRuleConverter.convertResultsToRules(results.incomplete, axeTags, wcagTagsToTaxaIndices, rulesDictionary); }; ResultToRuleConverter.convertResultsToRules = function (results, axeTags, wcagTagsToTaxaIndices, rulesDictionary) { if (results) { for (var _i = 0, results_1 = results; _i < results_1.length; _i++) { var result = results_1[_i]; rulesDictionary[result.id] = ResultToRuleConverter.convertAxeResultToSarifRule(axeTags, wcagTagsToTaxaIndices, result); } } }; ResultToRuleConverter.convertAxeResultToSarifRule = function (axeTags, wcagTagsToTaxaIndices, result) { return { id: result.id, name: result.help, fullDescription: { text: result.description + '.', }, helpUri: result.helpUrl, relationships: ResultToRuleConverter.getRuleRelationshipsFromResultTags(axeTags, wcagTagsToTaxaIndices, result), }; }; ResultToRuleConverter.getRuleRelationshipsFromResultTags = function (axeTags, wcagTagsToTaxaIndices, result) { return result.tags .filter(function (tag) { return axeTags.indexOf(tag) != -1; }) .map(function (tag) { return { target: { id: tag, index: wcagTagsToTaxaIndices[tag], toolComponent: (0, wcag_taxonomy_provider_1.getWcagTaxonomyReference)(), }, kinds: ['superset'], }; }); }; return ResultToRuleConverter; }()); exports.ResultToRuleConverter = ResultToRuleConverter;