diff --git a/package.json b/package.json
index 19b1b11..03dee9e 100644
--- a/package.json
+++ b/package.json
@@ -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": {
diff --git a/tasks/htmllint.js b/tasks/htmllint.js
index a0a70ce..3aa05ef 100644
--- a/tasks/htmllint.js
+++ b/tasks/htmllint.js
@@ -5,6 +5,14 @@ const { readFileSync } = require('fs');
const template = readFileSync(path.join(__dirname, 'template.html'), 'utf8')
+function escapeHTML(str) {
+ return String(str)
+ .replace(/&/g, '&')
+ .replace(//g, '>')
+ .replace(/"/g, '"');
+}
+
function sortOccurrences(a, b) {
return b.count - a.count;
};
@@ -12,11 +20,13 @@ function sortOccurrences(a, b) {
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;
@@ -36,18 +46,19 @@ function formatOccurrences(result) {
var summary =
'
' +
'
'+
- '
Most common errors
' +
+ '
Most common errors (link)
' +
'
' +
' ';
occurrences.forEach(function(occurrence, index) {
- var message = occurrence.message.split('<').join('<').split('"').join('"');
+ var message = escapeHTML(occurrence.message);
summary +=
' ' +
' ' + occurrence.code + ' - ' + message + ' | ' +
' ' + occurrence.count + ' | ' +
'
';
});
+
summary +=
' ' +
'
' +
@@ -56,6 +67,10 @@ function formatOccurrences(result) {
'
' +
' ' +
' ' +
+ ' Total number of errors | ' +
+ ' ' + errorCount +' | ' +
+ '
' +
+ ' ' +
' Files with errors | ' +
' ' + filesWithErrors + ' | ' +
'
' +
@@ -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('<');
- const message = issue.msg.split('<').join('<').split('"').join('"');
+ const extract = escapeHTML(issue.code);
+ const message = escapeHTML(issue.msg);
const line = issue.line;
const column = issue.column;
const position = 'line: ' + line + ', column: ' + column;
@@ -97,23 +112,29 @@ function formatIssues (issues, panelColor) {
}
function formatFile (file) {
- const returnedErrors = formatIssues(file.errors, 'danger');
-
- const content =
- '' +
- ' ' +
- ' ' + file.name + '' +
- ' | ' +
- ' ' + file.errors.length + ' | ' +
- '
' +
- '' +
- ' ' +
- ' ' +
- ' ' + formatIssues(file.errors) +
- ' ' +
- ' ' +
- ' | ' +
- '
\n';
+ const returnedErrors = formatIssues(file.errors);
+
+ if (file.errors.length > 0) {
+ return '' +
+ ' ' +
+ ' ' + file.name + '' +
+ ' | ' +
+ ' ' + file.errors.length + ' | ' +
+ '
' +
+ '' +
+ ' ' +
+ ' ' +
+ ' ' + formatIssues(file.errors) +
+ ' ' +
+ ' ' +
+ ' | ' +
+ '
\n';
+ } else {
+ return '' +
+ ' ' + file.name + ' | ' +
+ ' ' + file.errors.length + ' | ' +
+ '
';
+ }
return content;
}
function sortErrors(a,b) {