From 805655d588f800a125dd738fb9c0dbc13be67c0c Mon Sep 17 00:00:00 2001 From: Ronny Thomassen Date: Tue, 19 Nov 2019 11:59:39 +0100 Subject: [PATCH] succes color added total number of errors added --- package.json | 8 +++--- tasks/htmllint.js | 67 +++++++++++++++++++++++++++++++---------------- 2 files changed, 48 insertions(+), 27 deletions(-) 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 += ' ' + ' ' + ' ' + ' '; }); + summary += ' ' + '
' + occurrence.code + ' - ' + message + '' + occurrence.count + '
' + @@ -56,6 +67,10 @@ function formatOccurrences(result) { ' ' + ' ' + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + ' ' + ' ' + ' ' + @@ -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 = - '' + - ' ' + - ' ' + - '' + - '' + - ' ' + - '\n'; + const returnedErrors = formatIssues(file.errors); + + if (file.errors.length > 0) { + return '' + + ' ' + + ' ' + + '' + + '' + + ' ' + + '\n'; + } else { + return '' + + ' ' + + ' ' + + ''; + } return content; } function sortErrors(a,b) {
Total number of errors' + errorCount +'
Files with errors' + filesWithErrors + '
' + - ' ' + file.name + '' + - ' ' + file.errors.length + '
' + + ' ' + file.name + '' + + ' ' + file.errors.length + '
' + file.name + '' + file.errors.length + '