Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add jslint and define API for all validators (not tested)

  • Loading branch information...
commit e3b8fdebfc3c3072dc39bd1e30cd987dd28ce26d 1 parent cc5471e
@kof authored
View
3  .gitmodules
@@ -1,3 +1,6 @@
[submodule "tools/JSLint"]
path = tools/JSLint
url = https://github.com/douglascrockford/JSLint.git
+[submodule "deps/argsparser"]
+ path = deps/argsparser
+ url = git@github.com:kof/node-argsparser.git
View
0  conf/client.json
No changes.
View
33 conf/server.json
@@ -0,0 +1,33 @@
+{
+ "jslint": {
+ "bitwise": true,
+ "browser": false,
+ "cap": false,
+ "debug": false,
+ "devel": false,
+ "eqeqeq": true,
+ "es5": true,
+ "evil": true,
+ "forin": true,
+ "fragment": false,
+ "immed": true,
+ "indent": 4,
+ "laxbreak": false,
+ "maxlen": 90,
+ "nomen": false,
+ "newcap": true,
+ "on": false,
+ "onevar": true,
+ "passfail": true,
+ "plusplus": false,
+ "predef": ["global", "process", "require", "__dirname", "__filename", "module", "exports"],
+ "regexp": true,
+ "rhino": false,
+ "safe": false,
+ "strict": false,
+ "sub": false,
+ "undef": true,
+ "white": false,
+ "windows": false
+ }
+}
1  deps/argsparser
@@ -0,0 +1 @@
+Subproject commit 0bdc6d5a1813eea87a4065cf06a2b5e2f04b40d7
View
40 lib/index.js
@@ -0,0 +1,40 @@
+var fs = require("fs");
+
+var confPath = __dirname + "/../conf/";
+
+/**
+ * Run all checker
+ * @param {Array|String} files
+ * @param {String} confName
+ * @param {Function} callback
+ */
+exports.run = function( files, confName, callback ) {
+ var options = JSON.parse( fs.readFileSync(confPath + confName + ".json") ),
+ validator,
+ progress = {
+ all: 0,
+ done: 0
+ },
+ errors = [];
+
+ if ( typeof files === "string" ) {
+ files = [files];
+ }
+
+ for ( validator in options ) {
+ require(validator).run( files, options[validator], function( err ) {
+ if ( err ) {
+ errors.push(err);
+ }
+
+ progress.done++;
+
+ if ( progress.all === progress.done ) {
+ callback( errrors.length ? errors : false );
+ }
+ });
+ progress.all++;
+ }
+};
+
+
View
41 lib/jslint.js
@@ -0,0 +1,41 @@
+/**
+ * jslint wrapper for nodejs
+ *
+ * @author Oleg Slobodskoi aka Kof
+ */
+
+var fs = require( "fs" ),
+ util = require( "util" ),
+ Script = process.binding( "evals" ).Script;
+
+var jslintPath = __dirname + "/../tools/JSLint/fulljslint.js";
+
+// exec jslint
+new Script.runInThisContext( fs.readFileSync( jslintPath ), jslintPath );
+
+
+
+/**
+ * Run jslint checker
+ * @param {Array} files
+ * @param {String} confName
+ * @param {Function} callback
+ */
+exports.run = function( files, options, callback ) {
+
+ var err = [];
+
+ files.forEach( function( file ) {
+ var code = fs.readFileSync(file).toString().trim();
+
+ // there are errors
+ if ( JSLINT(code, options) === false ) {
+ err.push({
+ message: "jslint errors in file " + path,
+ errors: JSLINT.data().errors
+ });
+ }
+ });
+
+ callback(err.length>0 ? err : false);
+};
View
1  readme.md
@@ -8,6 +8,7 @@ Codenazi is highly configurable, so if you don't want to use some rules, you can
- all rules can be defined in one configuration ".json" file
- you can create many conf. files, because you might have different rules for different environments f.e. server and client.
- use of all available checker, independent of language it is written in, if you have one more - you can add it
+- unified errors reporting format
## Currently used tools
- JSLint http://www.jslint.com/lint.html
Please sign in to comment.
Something went wrong with that request. Please try again.