diff options
author | Zac Echola <zac.echola@so.mnscu.edu> | 2014-11-10 18:40:12 +0300 |
---|---|---|
committer | Zac Echola <zac.echola@so.mnscu.edu> | 2014-11-10 18:40:12 +0300 |
commit | e8b2a461077e8c43c094712dda17b0128c8ff529 (patch) | |
tree | 1881b4cc5b9d5af86eaca9b481d74d8910cf2e48 /tasks | |
parent | 792bb692eb6ac5e5b4ea0bc1624a2890ec5ff270 (diff) |
Bumps dependency, adding line/column nums
Also cleans up quite a bit of the noisiness from the output. It will now
pass silently and will only print when there are warnings or errors.
Diffstat (limited to 'tasks')
-rw-r--r-- | tasks/bootlint.js | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/tasks/bootlint.js b/tasks/bootlint.js index b82fa1c..1f2d813 100644 --- a/tasks/bootlint.js +++ b/tasks/bootlint.js @@ -12,29 +12,16 @@ module.exports = function(grunt) { var bootlint = require('bootlint'); var chalk = require('chalk'); - var msg = { - start: 'Validation started for ', - ok: 'Validation successful!', - done: 'No Bootlint errors!'.bold - }; grunt.registerMultiTask('bootlint', 'An HTML linter for Bootstrap projects', function() { var options = this.options({ stoponerror: false, relaxerror: [] }); - var totalErrCount = 0; - - var reporter = function(lint) { - var lintId = (lint.id[0] === 'E') ? chalk.bgGreen.white(lint.id) : chalk.bgRed.white(lint.id); - if (options.stoponerror) { - grunt.fail.warn(lintId, lint.message); - } else { - grunt.log.warn(lintId, lint.message); - totalErrCount++; - } - }; + var totalErrCount = 0; + var totalFileCount = 0; + var hardfail = false; // Iterate over all specified file groups. this.files.forEach(function(f) { @@ -49,16 +36,38 @@ module.exports = function(grunt) { }) .forEach(function(filepath) { + var src = grunt.file.read(filepath); - grunt.log.writeln(msg.start + filepath); + var reporter = function (lint) { + var lintId = (lint.id[0] === 'E') ? chalk.bgGreen.white(lint.id) : chalk.bgRed.white(lint.id); + var output = false; + if (lint.elements) { + lint.elements.each(function (_, element) { + var loc = element.startLocation; + grunt.log.warn(filepath + ":" + (loc.line + 1) + ":" + (loc.column + 1), lintId, lint.message); + totalErrCount++; + output = true; + }); + } + if (!output) { + grunt.log.warn(filepath + ":", lintId, lint.message); + totalErrCount++; + if (options.stoponerror) { + hardfail = true; + } + } + }; + bootlint.lintHtml(src, reporter, options.relaxerror); + totalFileCount++; }); if (totalErrCount > 0) { - grunt.log.writeln().fail(totalErrCount + ' lint errors found.'); + grunt.log.writeln().fail(totalErrCount + " lint error(s) found across " + totalFileCount + " file(s)."); grunt.log.writeln().fail('For details, look up the lint problem IDs in the Bootlint wiki: https://github.com/twbs/bootlint/wiki'); - } else { - grunt.log.writeln().success(msg.done); + if (hardfail) { + grunt.fail.warn('Too many bootlint errors.'); + } } }); }); |