From 40864ac83764cd1fa4704f239b15d69fcb1d62f5 Mon Sep 17 00:00:00 2001 From: Arthur Kay Date: Mon, 17 Dec 2012 21:49:39 -0600 Subject: [PATCH] First crack at Esprima support --- CHANGELOG | 4 +++ package.json | 9 +++--- src/esprima.js | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 src/esprima.js diff --git a/CHANGELOG b/CHANGELOG index f406511..64112fe 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,10 @@ VERSION 2.x =============== +Version 2.2.1 (December 17, 2012) - BREAKING CHANGES + - Added support for Esprima + + Version 2.2.0 (December 17, 2012) - BREAKING CHANGES - Changed configuration of linters - now using "linters" array - Broke supported linters into specific modules diff --git a/package.json b/package.json index a769b0f..185b180 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name" : "lintroller", "preferGlobal" : "true", - "version" : "2.2.0", + "version" : "2.2.1", "author" : "Arthur Kay ", "description" : "Lint your JavaScript code and output errors to a log file. Convenient for pre-commit hooks and build systems to maintain code quality.", @@ -25,8 +25,9 @@ }, "dependencies" : { - "jshint" : ">=0.9.1", - "jslint" : ">=0.1.9", - "fs" : ">=0.0.0" + "esprima" : ">=1.0.2", + "jshint" : ">=0.9.1", + "jslint" : ">=0.1.9", + "fs" : ">=0.0.0" } } \ No newline at end of file diff --git a/src/esprima.js b/src/esprima.js new file mode 100644 index 0000000..45a1fb1 --- /dev/null +++ b/src/esprima.js @@ -0,0 +1,83 @@ +var ESPRIMA = require('esprima'); + +var linter = { + + lib : ESPRIMA, + + /** + * @cfg + */ + options : { + + }, + + /** + * @private + */ + applyLintOptions : function (options) { + var i; + + if (!options) { + return false; + } + + for (i in options) { + if (options.hasOwnProperty(i)) { + this.options[i] = options[i]; + } + } + }, + + /** + * @private + */ + runLinter : function (parentModule) { + var j = 0, + errorList = ['=============== Running Esprima... ===============\n\n'], + file, js; + + parentModule.log('Running Esprima against code...', false); + + for (j; j < parentModule.files.length; j++) { + + file = parentModule.files[j]; + js = parentModule.fs.readFileSync(file, 'utf8'); + + //TODO: make this work... is that possible? + var i = 0, + result = this.lib.parse(js, this.options), + totalErrors = (result.errors) ? result.errors.length : 0, + error; + + if (!result) { + for (i; i < totalErrors; i++) { + error = this.lib.errors[i]; + + if (error) { + errorList.push( + file, + ' Line #: ' + error.line, + ' Char #: ' + error.character, + ' Reason: ' + error.reason, + '', + '' + ); + + if (parentModule.stopOnFirstError) { + break; + } + } + } + + if (parentModule.stopOnFirstError && errorList.length > 0) { + parentModule.announceErrors(errorList); + } + } + } + + return errorList; + } + +}; + +module.exports = linter; \ No newline at end of file