You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2012/04/20 02:08:14 UTC
[4/7] git commit: added jake hint task for jshinting the code
added jake hint task for jshinting the code
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/a5779e80
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/a5779e80
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/a5779e80
Branch: refs/heads/master
Commit: a5779e801fd02bb03a83ebc56c6f03aba82ee38a
Parents: 5322e90
Author: Fil Maj <ma...@gmail.com>
Authored: Wed Apr 18 09:30:21 2012 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Thu Apr 19 16:38:51 2012 -0700
----------------------------------------------------------------------
Jakefile | 92 +++++++++++++++++++++++++++++++++++++++++++++++++---
package.json | 3 +-
2 files changed, 88 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/a5779e80/Jakefile
----------------------------------------------------------------------
diff --git a/Jakefile b/Jakefile
index 3e62ff2..bbd09c6 100644
--- a/Jakefile
+++ b/Jakefile
@@ -1,8 +1,46 @@
-var util = require('util')
-var fs = require('fs')
-var childProcess = require('child_process')
-var path = require("path")
+var util = require('util'),
+ fs = require('fs'),
+ childProcess = require('child_process'),
+ path = require("path"),
+ hint = require('jshint'),
+ rexp_minified = new RegExp("\\.min\\.js$"),
+ rexp_src = new RegExp('\\.js$');
+
+
+function forEachFile(root, cbFile, cbDone) {
+ var count = 0;
+
+ function scan(name) {
+ ++count;
+
+ fs.stat(name, function (err, stats) {
+ if (err) cbFile(err);
+
+ if (stats.isDirectory()) {
+ fs.readdir(name, function (err, files) {
+ if (err) cbFile(err);
+
+ files.forEach(function (file) {
+ scan(path.join(name, file));
+ });
+ done();
+ });
+ } else if (stats.isFile()) {
+ cbFile(null, name, stats, done);
+ } else {
+ done();
+ }
+ });
+ }
+
+ function done() {
+ --count;
+ if (count === 0 && cbDone) cbDone();
+ }
+
+ scan(root);
+}
desc("runs build");
task('default', ['build','test'], function () {});
@@ -42,7 +80,7 @@ task('build', ['clean'], function () {
desc("prints a dalek");
task('dalek', ['set-cwd'], function () {
util.puts(fs.readFileSync("build/dalek", "utf-8"));
-})
+});
desc("runs the unit tests in node");
task('test', ['set-cwd'], require('./test/runner').node);
@@ -53,7 +91,49 @@ task('btest', ['set-cwd'], require('./test/runner').browser);
desc("make sure we're in the right directory");
task('set-cwd', [], function() {
if (__dirname != process.cwd()) {
- process.chdir(__dirname)
+ process.chdir(__dirname);
}
});
+// Taken shamelessly from Jakefile from https://github.com/marcenuc/sammy
+desc('Check sources with JSHint.');
+task('hint', function () {
+ var JSHINT = require('jshint').JSHINT;
+
+ function checkFile(file, cbDone) {
+ fs.readFile(file, 'utf8', function (err, src) {
+ if (err) throw err;
+
+ var res = [],
+ line;
+
+ if (!JSHINT(src)) {
+ res.push("\n" + file);
+ JSHINT.errors.forEach(function (e) {
+ if (e) {
+ if (line !== e.line) {
+ line = e.line;
+ res.push(line + ": " + e.evidence);
+ }
+ res.push("\t" + e.reason);
+ }
+ });
+ console.log(res.join('\n'));
+ }
+
+ cbDone();
+ });
+ }
+
+ forEachFile('lib', function (err, file, stats, cbDone) {
+ if (err) throw err;
+
+ if (rexp_minified.test(file) || !rexp_src.test(file)) {
+ cbDone();
+ } else {
+ checkFile(file, cbDone);
+ }
+ }, function() {
+ checkFile('Jakefile', complete);
+ });
+}, true);
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/a5779e80/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 86a4f6f..2d66d93 100644
--- a/package.json
+++ b/package.json
@@ -43,7 +43,8 @@
],
"dependencies": {
"jsdom":"0.2.10",
- "connect":"1.8.5"
+ "connect":"1.8.5",
+ "jshint":"0.6.1"
},
"devDependencies": {}
}