From 17379869eb5b9cd693a7efc4930107e9e06aa124 Mon Sep 17 00:00:00 2001 From: Yanis Wang Date: Wed, 7 Oct 2015 20:42:09 +0800 Subject: [PATCH] update to htmlhint v0.9.8 --- .editorconfig | 17 +++++++ package.json | 88 +++++++++++++++++----------------- tasks/htmlhint.js | 97 ++++++++++++++++++-------------------- test/fixtures/empty.html | 0 test/fixtures/invalid.html | 18 +++---- test/fixtures/valid.html | 18 +++---- 6 files changed, 125 insertions(+), 113 deletions(-) create mode 100644 .editorconfig delete mode 100644 test/fixtures/empty.html diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..5a13b97 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ +# EditorConfig helps developers define and maintain consistent +# coding styles between different editors and IDEs +# editorconfig.org + +root = true + +# Apply for all files +[*] + +charset = utf-8 + +indent_style = space +indent_size = 4 + +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true diff --git a/package.json b/package.json index 0568a94..c0e4279 100644 --- a/package.json +++ b/package.json @@ -1,44 +1,44 @@ -{ - "name": "grunt-htmlhint", - "description": "Validate html files with htmlhint.", - "version": "0.4.1", - "homepage": "https://github.com/yaniswang/grunt-htmlhint", - "author": { - "name": "Yanis Wang", - "email": "yanis.wang@gmail.com", - "url": "http://yaniswang.com/" - }, - "repository": { - "type": "git", - "url": "git@github.com:yaniswang/grunt-htmlhint.git" - }, - "bugs": { - "url": "https://github.com/yaniswang/grunt-htmlhint/issues" - }, - "licenses": [ - { - "type": "MIT", - "url": "https://github.com/yaniswang/grunt-htmlhint/blob/master/LICENSE-MIT" - } - ], - "main": "Gruntfile.js", - "engines": { - "node": ">= 0.8.0" - }, - "scripts": { - "test": "grunt --force" - }, - "devDependencies": { - "grunt-contrib-jshint": "~0.1.1", - "grunt": "~0.4.1" - }, - "peerDependencies": { - "grunt": "~0.4.1" - }, - "keywords": [ - "gruntplugin" - ], - "dependencies": { - "htmlhint": "0.9.6" - } -} +{ + "name": "grunt-htmlhint", + "description": "Validate html files with htmlhint.", + "version": "0.9.8", + "homepage": "https://github.com/yaniswang/grunt-htmlhint", + "author": { + "name": "Yanis Wang", + "email": "yanis.wang@gmail.com", + "url": "http://yaniswang.com/" + }, + "repository": { + "type": "git", + "url": "git@github.com:yaniswang/grunt-htmlhint.git" + }, + "bugs": { + "url": "https://github.com/yaniswang/grunt-htmlhint/issues" + }, + "licenses": [ + { + "type": "MIT", + "url": "https://github.com/yaniswang/grunt-htmlhint/blob/master/LICENSE-MIT" + } + ], + "main": "Gruntfile.js", + "engines": { + "node": ">= 0.8.0" + }, + "scripts": { + "test": "grunt --force" + }, + "devDependencies": { + "grunt-contrib-jshint": "~0.1.1", + "grunt": "~0.4.1" + }, + "peerDependencies": { + "grunt": "~0.4.1" + }, + "keywords": [ + "gruntplugin" + ], + "dependencies": { + "htmlhint": "0.9.8" + } +} diff --git a/tasks/htmlhint.js b/tasks/htmlhint.js index b5c11ae..bc5d5e2 100644 --- a/tasks/htmlhint.js +++ b/tasks/htmlhint.js @@ -10,64 +10,59 @@ module.exports = function(grunt) { - grunt.registerMultiTask('htmlhint', 'Validate html files with htmlhint.', function() { + grunt.registerMultiTask('htmlhint', 'Validate html files with htmlhint.', function() { - var HTMLHint = require("htmlhint").HTMLHint; - var options = this.options({ - force: false - }), - arrFilesSrc = this.filesSrc, - verbose = grunt.verbose; + var HTMLHint = require("htmlhint").HTMLHint; + var options = this.options({ + force: false + }), + arrFilesSrc = this.filesSrc, + verbose = grunt.verbose; - if (options.htmlhintrc) { - var rc = grunt.file.readJSON(options.htmlhintrc); - grunt.util._.defaults(options, rc); - delete options.htmlhintrc; - } + if (options.htmlhintrc) { + var rc = grunt.file.readJSON(options.htmlhintrc); + grunt.util._.defaults(options, rc); + delete options.htmlhintrc; + } - var force = options.force; - delete options.force; + var force = options.force; + delete options.force; - var hintCount = 0; - arrFilesSrc.forEach(function( filepath ) { - var file = grunt.file.read( filepath ), - msg = "Linting " + filepath + "...", - messages; - if (file.length) { - messages = HTMLHint.verify(file, options); - verbose.write( msg ); - if (messages.length > 0) { - verbose.or.write( msg ); - grunt.log.error(); - } else { - verbose.ok(); - } - messages.forEach(function( message ) { - grunt.log.writeln( "[".red + ( "L" + message.line ).yellow + ":".red + ( "C" + message.col ).yellow + "]".red + ' ' + message.message.yellow ); - var evidence = message.evidence, - col = message.col; - if (col === 0) { - evidence = '?'.inverse.red + evidence; - } else if (col > evidence.length) { - evidence = evidence + ' '.inverse.red; - } else { - evidence = evidence.slice(0, col - 1) + evidence[col - 1].inverse.red + evidence.slice(col); - } - grunt.log.writeln(evidence); - hintCount ++; + var hintCount = 0; + var fileCount = 0; + arrFilesSrc.forEach(function(filepath) { + var file = grunt.file.read(filepath), + msg = " " + filepath, + messages; + if (file.length) { + messages = HTMLHint.verify(file, options); + if (messages.length > 0) { + grunt.log.writeln(msg); + messages.forEach(function(hint) { + grunt.log.writeln(' L%d |%s', hint.line, hint.evidence.replace(/\t/g, ' ').grey); + grunt.log.writeln(' %s^ %s', repeatStr(String(hint.line).length + 3 + hint.col - 1), (hint.message + ' (' + hint.rule.id + ')')[hint.type === 'error' ? 'red' : 'yellow']); + hintCount++; + }); + grunt.log.writeln(''); + fileCount ++; + } + } }); - } - else{ - grunt.log.writeln( "Skipping empty file " + filepath); - } - }); - if ( hintCount > 0 ) { - return force; - } + if (hintCount > 0) { + grunt.log.error('%d errors in %d files'.red, hintCount, fileCount); + return force; + } + else{ + verbose.ok(); + } - grunt.log.ok(arrFilesSrc.length + ' file' + (arrFilesSrc.length === 1 ? '' : 's') + ' lint free.'); + grunt.log.ok(arrFilesSrc.length + ' file' + (arrFilesSrc.length === 1 ? '' : 's') + ' lint free.'); - }); + }); + + function repeatStr(n, str){ + return new Array(n + 1).join(str || ' '); + } }; diff --git a/test/fixtures/empty.html b/test/fixtures/empty.html deleted file mode 100644 index e69de29..0000000 diff --git a/test/fixtures/invalid.html b/test/fixtures/invalid.html index 8afadea..3acb87f 100644 --- a/test/fixtures/invalid.html +++ b/test/fixtures/invalid.html @@ -1,10 +1,10 @@ - - - - - - - -
- + + + + + + + +
+ \ No newline at end of file diff --git a/test/fixtures/valid.html b/test/fixtures/valid.html index 8b0ea84..fdf1981 100644 --- a/test/fixtures/valid.html +++ b/test/fixtures/valid.html @@ -1,10 +1,10 @@ - - - - - - - -
test
- + + + + + + + +
test
+ \ No newline at end of file