Skip to content

Commit

Permalink
add:
Browse files Browse the repository at this point in the history
1. change cli parameter: --plugin to --rulesdir
2. add formatter directory support
3. add formatters: compact, markdown
  • Loading branch information
yaniswang committed Oct 25, 2015
1 parent 80d1b8c commit de90962
Show file tree
Hide file tree
Showing 9 changed files with 320 additions and 178 deletions.
8 changes: 8 additions & 0 deletions CHANGE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
HTMLHint change log
====================

## ver 0.9.13 (2015-10-25)

add:

1. change cli parameter: `--plugin` to `--rulesdir`
2. add formatter directory support
3. add formatters: compact, markdown

## ver 0.9.10 (2015-10-12)

add:
Expand Down
52 changes: 52 additions & 0 deletions bin/formatters/checkstyle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright (c) 2015, Yanis Wang <[email protected]>
* MIT Licensed
*/
var xml = require('xml');

var formatter = {
onEnd: function(hintInfo){
var arrFiles = [];
var arrAllMessages = hintInfo.arrAllMessages;
arrAllMessages.forEach(function(fileInfo){
var arrMessages = fileInfo.messages;
var arrErrors = [];
arrMessages.forEach(function(message){
arrErrors.push({
error: {
_attr: {
line: message.line,
column: message.col,
severity: message.type,
message: message.message,
source: 'htmlhint.'+message.rule.id
}
}
});
});
arrFiles.push({
file: [
{
_attr: {
name: fileInfo.file
}
}
].concat(arrErrors)
});
});
var objXml = {
checkstyle: [
{
_attr: {
version: '4.3'
}
}
].concat(arrFiles)
};
console.log(xml(objXml, {
declaration: true,
indent: ' '
}));
}
};
module.exports = formatter;
26 changes: 26 additions & 0 deletions bin/formatters/compact.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright (c) 2015, Yanis Wang <[email protected]>
* MIT Licensed
*/
var formatter = {
onFileHint: function(result){
result.messages.forEach(function (message) {
console.log('%s: line %d, col %d, %s - %s (%s)',
result.file,
message.line,
message.col,
message.type,
message.message,
message.rule.id
);
});
},
onEnd: function(hintInfo){
var allHintCount = hintInfo.allHintCount;
if(allHintCount > 0){
console.log('');
console.log('%d problems', hintInfo.allHintCount);
}
}
};
module.exports = formatter;
37 changes: 37 additions & 0 deletions bin/formatters/default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Copyright (c) 2015, Yanis Wang <[email protected]>
* MIT Licensed
*/
var formatter = {
onStart: function(){
console.log('');
},
onConfigLoaded: function(config, configPath){
console.log(' Config loaded: %s', configPath.cyan);
console.log('');
},
onFileHint: function(result, HTMLHint){
console.log(' '+result.file.white);
var arrLogs = HTMLHint.format(result.messages, {
colors: true,
indent: 6
});
arrLogs.forEach(function(str){
console.log(str);
});
console.log('');
},
onEnd: function(hintInfo){
var allFileCount = hintInfo.allFileCount;
var allHintCount = hintInfo.allHintCount;
var allHintFileCount = hintInfo.allHintFileCount;
var time = hintInfo.time;
if(allHintCount > 0){
console.log('Scan %d files, found %d errors in %d files (%d ms)'.red, allFileCount, allHintCount, allHintFileCount, time);
}
else{
console.log('Scan %d files, without errors (%d ms).'.green, allFileCount, time);
}
}
};
module.exports = formatter;
10 changes: 10 additions & 0 deletions bin/formatters/json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Copyright (c) 2015, Yanis Wang <[email protected]>
* MIT Licensed
*/
var formatter = {
onEnd: function(hintInfo){
console.log(JSON.stringify(hintInfo.arrAllMessages));
}
};
module.exports = formatter;
55 changes: 55 additions & 0 deletions bin/formatters/junit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Copyright (c) 2015, Yanis Wang <[email protected]>
* MIT Licensed
*/
var xml = require('xml');

var formatter = {
onEnd: function(hintInfo, HTMLHint){
var arrTestcase = [];
var arrAllMessages = hintInfo.arrAllMessages;
arrAllMessages.forEach(function(fileInfo){
var arrMessages = fileInfo.messages;
var arrLogs = HTMLHint.format(arrMessages);
arrTestcase.push({
testcase: [
{
_attr: {
name: fileInfo.file,
time: (fileInfo.time / 1000).toFixed(3)
}
},
{
failure: {
_attr: {
message: 'Found '+arrMessages.length+' errors'
},
_cdata: arrLogs.join('\r\n')
}
}
]
});
});
var objXml = {
testsuites: [
{
testsuite: [
{
_attr: {
name: 'HTMLHint Tests',
time: (hintInfo.time / 1000).toFixed(3),
tests: hintInfo.allFileCount,
failures: arrAllMessages.length
}
}
].concat(arrTestcase)
}
]
};
console.log(xml(objXml, {
declaration: true,
indent: ' '
}));
}
};
module.exports = formatter;
40 changes: 40 additions & 0 deletions bin/formatters/markdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright (c) 2015, Yanis Wang <[email protected]>
* MIT Licensed
*/
var formatter = {
onEnd: function(hintInfo, HTMLHint){
console.log('# TOC');
var arrToc = [];
var arrContents = [];
var arrAllMessages = hintInfo.arrAllMessages;
arrAllMessages.forEach(function(fileInfo){
var filePath = fileInfo.file;
var arrMessages = fileInfo.messages;
var errorCount = 0;
var warningCount = 0;
arrMessages.forEach(function(message){
if(message.type === 'error'){
errorCount ++;
}
else{
warningCount ++;
}
});
arrToc.push(' - ['+filePath+'](#'+filePath+')');
arrContents.push('<a name="'+filePath+'" />');
arrContents.push('# '+filePath);
arrContents.push('');
arrContents.push('Found '+errorCount+' errors, '+warningCount+' warnings');
var arrLogs = HTMLHint.format(arrMessages);
arrContents.push('');
arrLogs.forEach(function(log){
arrContents.push(' '+log);
});
arrContents.push('');
});
console.log(arrToc.join('\r\n')+'\r\n');
console.log(arrContents.join('\r\n'));
}
};
module.exports = formatter;
24 changes: 24 additions & 0 deletions bin/formatters/unix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright (c) 2015, Yanis Wang <[email protected]>
* MIT Licensed
*/
var formatter = {
onFileHint: function(result){
result.messages.forEach(function (message) {
console.log([
result.file,
message.line,
message.col,
" " + message.message + ' ['+message.type+'/'+message.rule.id+']'
].join(":"));
});
},
onEnd: function(hintInfo){
var allHintCount = hintInfo.allHintCount;
if(allHintCount > 0){
console.log('');
console.log('%d problems', hintInfo.allHintCount);
}
}
};
module.exports = formatter;
Loading

0 comments on commit de90962

Please sign in to comment.