Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified Contrib/PhantomJS/HTMLCS_Run.js
100644 → 100755
Empty file.
14 changes: 12 additions & 2 deletions Contrib/PhantomJS/runner.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
var HTMLCS_RUNNER = new function() {
this.run = function(standard) {
this.run = function(standard, callback) {
var self = this;

// At the moment, it passes the whole DOM document.
HTMLCS.process(standard, document, function() {
var messages = HTMLCS.getMessages();
var length = messages.length;
var msgCount = {};
msgCount[HTMLCS.ERROR] = 0;
msgCount[HTMLCS.WARNING] = 0;
msgCount[HTMLCS.NOTICE] = 0;

for (var i = 0; i < length; i++) {
self.output(messages[i]);
msgCount[messages[i].type]++;
}

console.log('Errors: ' + msgCount[HTMLCS.ERROR] + ', Warnings: ' + msgCount[HTMLCS.WARNING] +
', Notices: ' + msgCount[HTMLCS.NOTICE]);
console.log('done');
}, function() {
console.log('Something in HTML_CodeSniffer failed to parse. Cannot run.');
console.log('done');
});
};
Expand Down
42 changes: 25 additions & 17 deletions HTMLCS.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var HTMLCS = new function()
* @param {String|Node} An HTML string or a DOM node object.
* @param {Function} The function that will be called when the testing is completed.
*/
this.process = function(standard, content, callback) {
this.process = function(standard, content, callback, failCallback) {
// Clear previous runs.
_standards = {};
_sniffs = [];
Expand All @@ -52,7 +52,7 @@ var HTMLCS = new function()
} else {
this.loadStandard(standard, function() {
HTMLCS.run(callback, content);
});
}, failCallback);
}
};

Expand All @@ -62,15 +62,15 @@ var HTMLCS = new function()
* @param {String} standard The name of the standard to load.
* @param {Function} callback The function to call once the standard is loaded.
*/
this.loadStandard = function(standard, callback) {
this.loadStandard = function(standard, callback, failCallback) {
if (!standard) {
return false;
}

_includeStandard(standard, function() {
_standard = standard;
callback.call(this);
});
}, failCallback);
};

/**
Expand Down Expand Up @@ -300,7 +300,7 @@ var HTMLCS = new function()
* @param {Function} callback The function to call once the standard is included.
* @param {Object} options The options for the standard (e.g. exclude sniffs).
*/
var _includeStandard = function(standard, callback, options) {
var _includeStandard = function(standard, callback, failCallback, options) {
if (standard.indexOf('http') !== 0) {
standard = _getStandardPath(standard);
}//end id
Expand All @@ -310,12 +310,12 @@ var HTMLCS = new function()
var ruleSet = window['HTMLCS_' + parts[(parts.length - 2)]];
if (ruleSet) {
// Already included.
_registerStandard(standard, callback, options);
_registerStandard(standard, callback, failCallback, options);
} else {
_includeScript(standard, function() {
// Script is included now register the standard.
_registerStandard(standard, callback, options);
});
_registerStandard(standard, callback, failCallback, options);
}, failCallback);
}//end if
};

Expand All @@ -326,7 +326,7 @@ var HTMLCS = new function()
* @param {Function} callback The function to call once the standard is registered.
* @param {Object} options The options for the standard (e.g. exclude sniffs).
*/
var _registerStandard = function(standard, callback, options) {
var _registerStandard = function(standard, callback, failCallback, options) {
// Get the object name.
var parts = standard.split('/');

Expand Down Expand Up @@ -364,7 +364,7 @@ var HTMLCS = new function()

// Register the sniffs for this standard.
var sniffs = ruleSet.sniffs.slice(0, ruleSet.sniffs.length);
_registerSniffs(standard, sniffs, callback);
_registerSniffs(standard, sniffs, callback, failCallback);
};

/**
Expand All @@ -374,7 +374,7 @@ var HTMLCS = new function()
* @param {Array} sniffs List of sniffs to register.
* @param {Function} callback The function to call once the sniffs are registered.
*/
var _registerSniffs = function(standard, sniffs, callback) {
var _registerSniffs = function(standard, sniffs, callback, failCallback) {
if (sniffs.length === 0) {
callback.call(this);
return;
Expand All @@ -383,8 +383,8 @@ var HTMLCS = new function()
// Include and register sniffs.
var sniff = sniffs.shift();
_loadSniffFile(standard, sniff, function() {
_registerSniffs(standard, sniffs, callback);
});
_registerSniffs(standard, sniffs, callback, failCallback);
}, failCallback);
};

/**
Expand All @@ -395,7 +395,7 @@ var HTMLCS = new function()
* and object specifying another standard.
* @param {Function} callback The function to call once the sniff is included and registered.
*/
var _loadSniffFile = function(standard, sniff, callback) {
var _loadSniffFile = function(standard, sniff, callback, failCallback) {
if (typeof sniff === 'string') {
var sniffObj = _getSniff(standard, sniff);
var cb = function() {
Expand All @@ -407,7 +407,7 @@ var HTMLCS = new function()
if (sniffObj) {
cb();
} else {
_includeScript(_getSniffPath(standard, sniff), cb);
_includeScript(_getSniffPath(standard, sniff), cb, failCallback);
}
} else {
// Including a whole other standard.
Expand All @@ -420,7 +420,7 @@ var HTMLCS = new function()
}

callback.call(this);
}, {
}, failCallback, {
exclude: sniff.exclude,
include: sniff.include
});
Expand Down Expand Up @@ -542,14 +542,22 @@ var HTMLCS = new function()
* @param {String} src The URL to the JS file.
* @param {Function} callback The function to call once the script is loaded.
*/
var _includeScript = function(src, callback) {
var _includeScript = function(src, callback, failCallback) {
var script = document.createElement('script');
script.onload = function() {
script.onload = null;
script.onreadystatechange = null;
callback.call(this);
};

script.onerror = function() {
script.onload = null;
script.onreadystatechange = null;
if (failCallback) {
failCallback.call(this);
}
};

script.onreadystatechange = function() {
if (/^(complete|loaded)$/.test(this.readyState) === true) {
script.onreadystatechange = null;
Expand Down
Loading