Skip to content

Commit

Permalink
support plugin: htmlhint --plugin ./plugins/
Browse files Browse the repository at this point in the history
  • Loading branch information
yaniswang committed Oct 11, 2015
1 parent f4b4eec commit 5200522
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGE.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
HTMLHint change log
====================

## ver 0.9.10 (2015-10-10)
## ver 0.9.10 (2015-10-11)

add:

1. attr-unsafe-chars(rule): show unsafe code in message
2. support glob pattern for cli
3. support format as custom: json, junit, checkstyle
4. support plugin: `htmlhint --plugin ./plugins/`

fix:

Expand Down
38 changes: 38 additions & 0 deletions bin/htmlhint
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ function hintTargets(arrTargets, options){
var allHintCount = 0;
var startTime = new Date().getTime();

// load plugins
var pluginPath = options.plugin;
if(pluginPath){
loadPlugins(pluginPath);
}

// custom format
var format = options.format;
var arrAllMessages = [];
Expand Down Expand Up @@ -125,6 +131,38 @@ function hintTargets(arrTargets, options){
});
}

// load plugins
function loadPlugins(pluginPath){
pluginPath = pluginPath.replace(/\\/g, '/');
if(fs.existsSync(pluginPath)){
if(fs.statSync(pluginPath).isDirectory()){
pluginPath += /\/$/.test(pluginPath)?'':'/';
pluginPath += '**/*.js';
var arrFiles = glob.sync(pluginPath, {
'dot': false,
'nodir': true,
'strict': false,
'silent': true
});
arrFiles.forEach(function(file){
loadPlugin(file);
});
}
else{
loadPlugin(pluginPath);
}
}
}

function loadPlugin(filepath){
filepath = path.resolve(filepath);
try{
var plugin = require(filepath);
plugin(HTMLHint);
}
catch(e){}
}

// output as custom format
function formatResult(hintInfo, format){
switch(format){
Expand Down

0 comments on commit 5200522

Please sign in to comment.