-
-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. change cli parameter: --plugin to --rulesdir 2. add formatter directory support 3. add formatters: compact, markdown
- Loading branch information
Showing
9 changed files
with
320 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.