Skip to content

Commit

Permalink
succes color added
Browse files Browse the repository at this point in the history
total number of errors added
  • Loading branch information
RonnyTh committed Nov 19, 2019
1 parent 7b88b5a commit 805655d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 27 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "grunt-htmllint",
"description": "A grunt plugin for the unofficial HTML5 linter.",
"version": "0.3.1",
"homepage": "https://github.com/htmllint/grunt-htmllint",
"version": "0.3.2",
"homepage": "https://github.com/breinbv/grunt-htmllint",
"repository": {
"type": "git",
"url": "https://github.com/htmllint/grunt-htmllint.git"
"url": "https://github.com/breinbv/grunt-htmllint.git"
},
"bugs": {
"url": "https://github.com/htmllint/grunt-htmllint/issues"
"url": "https://github.com/breinbv/grunt-htmllint/issues"
},
"license": "ISC",
"engines": {
Expand Down
67 changes: 44 additions & 23 deletions tasks/htmllint.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,28 @@ const { readFileSync } = require('fs');

const template = readFileSync(path.join(__dirname, 'template.html'), 'utf8')

function escapeHTML(str) {
return String(str)
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
}

function sortOccurrences(a, b) {
return b.count - a.count;
};

function formatOccurrences(result) {
var occurrences = [];
var filesWithErrors = 0;

var errorCount = 0;
result.files.forEach(function (file) {
if (file.errors.length > 0) {
filesWithErrors ++;
}
errorCount += file.errors.length;

file.errors.forEach(function(error) {
var foundOccurrence = false;

Expand All @@ -36,18 +46,19 @@ function formatOccurrences(result) {
var summary =
'<div class="table-wrapper occurrences">' +
' <div class="table-column">'+
' <h3>Most common errors</h3>' +
' <h3>Most common errors <a href="https://github.com/htmllint/htmllint/wiki/Option-by-Error-Code">(link)</a></h3>' +
' <table class="summary-table">' +
' <tbody>';

occurrences.forEach(function(occurrence, index) {
var message = occurrence.message.split('<').join('&lt;').split('"').join('&quot;');
var message = escapeHTML(occurrence.message);
summary +=
' <tr class="occurrence row-' + index + '">' +
' <td>' + occurrence.code + ' - ' + message + '</td>' +
' <td>' + occurrence.count + '</td>' +
' </tr>';
});

summary +=
' </tbody>' +
' </table>' +
Expand All @@ -56,6 +67,10 @@ function formatOccurrences(result) {
' <table class="summary-table">' +
' <tbody>' +
' <tr>' +
' <td>Total number of errors</td>' +
' <td>' + errorCount +'</td>' +
' </tr>' +
' <tr>' +
' <td>Files with errors</td>' +
' <td>' + filesWithErrors + '</td>' +
' </tr>' +
Expand All @@ -77,10 +92,10 @@ function formatOccurrences(result) {
return summary;
}

function formatIssues (issues, panelColor) {
function formatIssues (issues) {
return issues.map(issue => {
const extract = issue.code.split('<').join('&lt;');
const message = issue.msg.split('<').join('&lt;').split('"').join('&quot;');
const extract = escapeHTML(issue.code);
const message = escapeHTML(issue.msg);
const line = issue.line;
const column = issue.column;
const position = 'line: ' + line + ', column: ' + column;
Expand All @@ -97,23 +112,29 @@ function formatIssues (issues, panelColor) {
}

function formatFile (file) {
const returnedErrors = formatIssues(file.errors, 'danger');

const content =
'<tr class="danger">' +
' <td>' +
' <a class="toggle-link" href="javascript:;" onclick="toggleDetails(this)">' + file.name + '</a>' +
' </td>' +
' <td>' + file.errors.length + '</td>' +
'</tr>' +
'<tr class="details-row hidden">' +
' <td colspan="2">' +
' <table class="details-table">' +
' <tbody>' + formatIssues(file.errors) +
' </tbody>' +
' </table>' +
' </td>' +
'</tr>\n';
const returnedErrors = formatIssues(file.errors);

if (file.errors.length > 0) {
return '<tr class="danger">' +
' <td>' +
' <a class="toggle-link" href="javascript:;" onclick="toggleDetails(this)">' + file.name + '</a>' +
' </td>' +
' <td>' + file.errors.length + '</td>' +
'</tr>' +
'<tr class="details-row hidden">' +
' <td colspan="2">' +
' <table class="details-table">' +
' <tbody>' + formatIssues(file.errors) +
' </tbody>' +
' </table>' +
' </td>' +
'</tr>\n';
} else {
return '<tr class="success">' +
' <td>' + file.name + '</td>' +
' <td>' + file.errors.length + '</td>' +
'</tr>';
}
return content;
}
function sortErrors(a,b) {
Expand Down

0 comments on commit 805655d

Please sign in to comment.