diff --git a/CHANGE.md b/CHANGE.md index d5b6d49d9..feabc00a5 100644 --- a/CHANGE.md +++ b/CHANGE.md @@ -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: diff --git a/bin/htmlhint b/bin/htmlhint index 5608d446d..00545a84f 100755 --- a/bin/htmlhint +++ b/bin/htmlhint @@ -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 = []; @@ -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){