Skip to content

Commit

Permalink
update to htmlhint v0.9.8
Browse files Browse the repository at this point in the history
  • Loading branch information
yaniswang committed Oct 7, 2015
1 parent ee3713b commit 1737986
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 113 deletions.
17 changes: 17 additions & 0 deletions .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
88 changes: 44 additions & 44 deletions 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"
}
}
97 changes: 46 additions & 51 deletions tasks/htmlhint.js
Expand Up @@ -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 || ' ');
}
};
Empty file removed test/fixtures/empty.html
Empty file.
18 changes: 9 additions & 9 deletions test/fixtures/invalid.html
@@ -1,10 +1,10 @@
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<ul><li></ul>
<div>
</body>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<ul><li></ul>
<div>
</body>
</html>
18 changes: 9 additions & 9 deletions test/fixtures/valid.html
@@ -1,10 +1,10 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div>test</div>
</body>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div>test</div>
</body>
</html>

0 comments on commit 1737986

Please sign in to comment.