Permalink
Browse files

First crack at Esprima support

  • Loading branch information...
1 parent 8ab8d87 commit 40864ac83764cd1fa4704f239b15d69fcb1d62f5 @arthurakay committed Dec 18, 2012
Showing with 92 additions and 4 deletions.
  1. +4 −0 CHANGELOG
  2. +5 −4 package.json
  3. +83 −0 src/esprima.js
View
@@ -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
View
@@ -1,7 +1,7 @@
{
"name" : "lintroller",
"preferGlobal" : "true",
- "version" : "2.2.0",
+ "version" : "2.2.1",
"author" : "Arthur Kay <art@akawebdesign.com>",
"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"
}
}
View
@@ -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;

0 comments on commit 40864ac

Please sign in to comment.