UNPKG

axe-sarif-converter

Version:

Convert axe-core accessibility scan results to the SARIF format

42 lines (41 loc) 1.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.formatSarifResultMessage = formatSarifResultMessage; var string_utils_1 = require("./string-utils"); function formatSarifResultMessage(node, kind) { var textArray = []; var markdownArray = []; if (kind === 'fail') { var allAndNone = node.all.concat(node.none); formatSarifCheckResultsMessage('Fix all of the following:', allAndNone, textArray, markdownArray); formatSarifCheckResultsMessage('Fix any of the following:', node.any, textArray, markdownArray); } else { var allNodes = node.all .concat(node.none) .concat(node.any); formatSarifCheckResultsMessage('The following tests passed:', allNodes, textArray, markdownArray); } return { text: textArray.join(' '), markdown: markdownArray.join('\n\n'), }; } function formatSarifCheckResultsMessage(heading, checkResults, textArray, markdownArray) { if (checkResults.length > 0) { var textLines = []; var markdownLines = []; textLines.push(heading); markdownLines.push((0, string_utils_1.escapeForMarkdown)(heading)); for (var _i = 0, checkResults_1 = checkResults; _i < checkResults_1.length; _i++) { var checkResult = checkResults_1[_i]; var message = (0, string_utils_1.isNotEmpty)(checkResult.message) ? checkResult.message : checkResult.id; textLines.push(message + '.'); markdownLines.push('- ' + (0, string_utils_1.escapeForMarkdown)(message) + '.'); } textArray.push(textLines.join(' ')); markdownArray.push(markdownLines.join('\n')); } }