Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix or override jshint gripes

  • Loading branch information...
commit 6d33b14614d5bed05fbca11f654e764a8fde6ca3 1 parent 3872c81
@lawnsea lawnsea authored
View
7 Gruntfile.js
@@ -34,7 +34,12 @@ module.exports = function (grunt) {
phantom_libs: {
src: ['lib/bootstrap.js', 'lib/bootstrap/**/*.js'],
options: {
- phantom: true
+ phantom: true,
+ browser: true,
+ globals: {
+ patchRequire: true,
+ module: true
+ }
}
},
tests: {
View
5 lib/bootstrap.js
@@ -1,4 +1,4 @@
-function emit(event) {
+function emit() {
var args = Array.prototype.slice.call(arguments);
console.log(JSON.stringify({
@@ -15,6 +15,7 @@ phantom.onError = function bootstrapOnError(msg, trace) {
// source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
Function.prototype.bind = function (oThis) {
+ /* jshint newcap: false, laxbreak: true */
if (typeof this !== "function") {
// closest thing possible to the ECMAScript 5 internal IsCallable function
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
@@ -39,8 +40,6 @@ Function.prototype.bind = function (oThis) {
var options = phantom.casperArgs.options;
phantom.requireBase = options.spooky_lib + 'node_modules/';
var emit = require(options.spooky_lib + 'lib/bootstrap/emit').emit;
-var system = require('system');
-var utils = require('utils');
var transport = (options.transport || '').toLowerCase();
var server;
View
14 lib/bootstrap/casper.js
@@ -4,6 +4,7 @@ if (phantom.casperVersion.major >= 1 &&
require = patchRequire(require);
}
+var options = phantom.casperArgs.options;
var createFunction =
require(options.spooky_lib + 'lib/bootstrap/create-function');
var casper = require('casper');
@@ -75,17 +76,18 @@ function callMethod(method, spec) {
instance[method].apply(instance, args);
return true;
-};
+}
var methods = {};
for (var k in methodsToProvide) {
+ /* jshint loopfunc: true */
methods[k] = (function (method, spec) {
return function () {
var args = [method, spec].
concat(Array.prototype.slice.call(arguments));
return callMethod.apply(null, args);
- }
+ };
})(k, methodsToProvide[k]);
}
@@ -112,10 +114,10 @@ function getCreateFn(server) {
server._instance = instance = casper.create(options);
instance.emit = function () {
var args = Array.prototype.slice.apply(arguments);
- if (args[0] === 'starting') {
- server.stop && server.stop();
- } else if (args[0] === 'run.complete') {
- server.start && server.start();
+ if (args[0] === 'starting' && server.stop) {
+ server.stop();
+ } else if (args[0] === 'run.complete' && server.start) {
+ server.start();
}
try {
View
7 lib/bootstrap/create-function.js
@@ -2,15 +2,17 @@
* Create a function from a string
*/
var evalFunction = (function () {
+ /* jshint unused: false */
// shadow global symbols
var evalFunction;
var createFunction;
return function (contextSrc, functionSrc) {
+ /* jshint evil: true */
var src = '(function () {\n' +
contextSrc +
'return ' + functionSrc + ';' +
- '}())'
+ '}())';
return eval(src);
};
@@ -45,7 +47,6 @@ var createFunction = (function () {
args = parsed[2].split(/\s*,\s*/);
body = parsed[3].replace(newlineTokenPattern, '\n');
- var fn = Function.apply(null, args.concat(body));
return ['function', name, '(', args.join(', '), ')', '{', body, '}'].join(' ');
}
@@ -71,7 +72,7 @@ var createFunction = (function () {
return function (fn) {
return fn ? parseFunction(fn) : void undefined;
- }
+ };
}());
module.exports = createFunction;
View
2  lib/bootstrap/emit.js
@@ -1,4 +1,4 @@
-function emit(event) {
+function emit() {
var args = Array.prototype.slice.call(arguments);
console.log(JSON.stringify({
View
3  lib/bootstrap/http-server.js
@@ -1,3 +1,4 @@
+var options = phantom.casperArgs.options;
var emit = require(options.spooky_lib + 'lib/bootstrap/emit').emit;
var port = options.port || 8080;
@@ -21,7 +22,7 @@ function respond(response, code, body) {
response.close();
}
-var service = require('webserver').create().
+require('webserver').create().
listen(port, function (request, response) {
var method = request.method.toUpperCase();
View
5 lib/bootstrap/stdio-server.js
@@ -1,6 +1,7 @@
var STDIN_POLL_INTERVAL = 10;
var stdin = require('system').stdin;
+var options = phantom.casperArgs.options;
var Stream = require(options.spooky_lib + 'lib/stream');
var stream = new Stream();
@@ -9,10 +10,6 @@ stream.write = function (s) {
return true;
};
-function timestamp() {
- return (new Date()).toISOString();
-}
-
function loop() {
var line = stdin.readLine();
var message;
View
96 lib/spooky.js
@@ -53,6 +53,38 @@ function isJsonRpcResponse(s) {
return false;
}
+function isFunctionTuple(a) {
+ return _.isArray(a) &&
+ a.length === 2 &&
+ _.isObject(a[0]) &&
+ _.isFunction(a[1]);
+}
+
+function serializeFunctions(x) {
+ if (_.isFunction(x)) {
+ x = x.toString();
+ } else if (isFunctionTuple(x)) {
+ x[1] = x[1].toString();
+ }
+
+ return x;
+}
+
+// serialize function values recursively
+function serializeMethods(o) {
+ var v;
+
+ for (var k in o) {
+ v = o[k];
+
+ if (_.isObject(v) && !_.isArray(v) && !_.isFunction(v)) {
+ serializeMethods(v);
+ } else {
+ o[k] = serializeFunctions(v);
+ }
+ }
+}
+
function Spooky(options, callback) {
EventEmitter.call(this);
this.options = options = _.defaults(_.clone(options || {}), defaults);
@@ -90,8 +122,6 @@ function Spooky(options, callback) {
// must terminate requests with a linefeed
this._rpcClient._send = function _send (request) {
- var success;
-
if (this._server.full) {
this._server.buffer.push(request);
} else {
@@ -115,19 +145,19 @@ function Spooky(options, callback) {
new FilteredStream(this._child.stdout, isJsonRpcRequest)));
this._rpcServer.provide({
- emit: (function (event) {
+ emit: function () {
this.emit.apply(this, arguments);
return true;
- }).bind(this)
+ }.bind(this)
});
- this.once('ready', (function () {
+ this.once('ready', function () {
this._call('create',
this._onCreate.bind(this, callback),
options.casper
);
- }).bind(this));
+ }.bind(this));
}
util.inherits(Spooky, EventEmitter);
@@ -136,7 +166,7 @@ Spooky._instances = {};
Spooky._nextInstanceId = 0;
// clean up if spooky dies
-process.on('exit', function (code, signal) {
+process.on('exit', function () {
_.each(Spooky._instances, function (server) {
server.kill();
});
@@ -162,18 +192,18 @@ Spooky.prototype._spawnChild = function () {
var stdout = child.stdout;
stdout.setEncoding('utf8');
child.stdout = new Stream();
- carrier.carry(stdout).on('line', (function (line) {
+ carrier.carry(stdout).on('line', function (line) {
this.stdout.emit('data', line);
- }).bind(child));
+ }.bind(child));
// emit anything that isn't JSON-RPC traffic as a console event
(new FilteredStream(child.stdout, function (data) {
return !isJsonRpcResponse(data) && !isJsonRpcRequest(data);
- })).on('data', (function (data) {
+ })).on('data', function (data) {
this.emit('console', data.toString());
- }).bind(this));
+ }.bind(this));
- child.on('exit', (function (code, signal) {
+ child.on('exit', function (code, signal) {
var e;
if (code) {
@@ -184,7 +214,7 @@ Spooky.prototype._spawnChild = function () {
};
this.emit('error', e);
}
- }).bind(this));
+ }.bind(this));
return child;
};
@@ -230,7 +260,7 @@ Spooky.prototype._call = function (method, callback) {
Spooky.prototype._callWorker = function (options, callback) {
var userCallback = options.callback;
- options.callback = (function (error, response) {
+ options.callback = function (error, response) {
if (userCallback) {
userCallback.apply(this, arguments);
}
@@ -240,7 +270,7 @@ Spooky.prototype._callWorker = function (options, callback) {
}
callback(error, response);
- }).bind(this);
+ }.bind(this);
//call.apply(this, params);
this._rpcClient.request(options);
@@ -265,40 +295,4 @@ Spooky.prototype._onCreate = function (callback, error, response) {
}
};
-function defaultCallback(error, response) {
- console.log(error, response);
-}
-
-function isFunctionTuple(a) {
- return _.isArray(a) &&
- a.length === 2 &&
- _.isObject(a[0]) &&
- _.isFunction(a[1]);
-}
-
-function serializeFunctions(x) {
- if (_.isFunction(x)) {
- x = x.toString();
- } else if (isFunctionTuple(x)) {
- x[1] = x[1].toString();
- }
-
- return x;
-}
-
-// serialize function values recursively
-function serializeMethods(o) {
- var v;
-
- for (var k in o) {
- v = o[k];
-
- if (_.isObject(v) && !_.isArray(v) && !_.isFunction(v)) {
- serializeMethods(v);
- } else {
- o[k] = serializeFunctions(v);
- }
- }
-}
-
module.exports = Spooky;
View
10 lib/spooky/filtered-stream.js
@@ -1,8 +1,8 @@
var stream = require('readable-stream');
-FilteredStream.prototype = Object.create(stream.Transform.prototype, {
- constructor: { value: FilteredStream }
- });
+function nopFilter() {
+ return true;
+}
function FilteredStream(source, filter, options) {
options = options || {};
@@ -14,6 +14,10 @@ function FilteredStream(source, filter, options) {
stream.Transform.call(this, options);
}
+FilteredStream.prototype = Object.create(stream.Transform.prototype, {
+ constructor: { value: FilteredStream }
+ });
+
FilteredStream.prototype._transform = function(chunk, encoding, callback) {
if (this.filter(chunk) === true) {
this.push(chunk);
View
4 lib/spooky/request-stream.js
@@ -42,10 +42,10 @@ RequestStream.prototype._onResponse = function onResponse(callback, response) {
var result = '';
response.on('data', function (data) { result += data; });
- response.on('end', (function () {
+ response.on('end', function () {
//console.log(result);
this.emit('data', result);
- }).bind(this));
+ }.bind(this));
};
RequestStream.prototype.end = function end(string) {
View
4 tests/test/bootstrap.js
@@ -10,7 +10,7 @@ describe('the PhantomJS bootstrap script', function () {
// expect child to exit non-zero
var exited = false;
- child.on('exit', function (code, signal) {
+ child.on('exit', function (code) {
expect(code).not.to.be(0);
exited = true;
@@ -40,7 +40,7 @@ describe('the PhantomJS bootstrap script', function () {
// expect child to exit non-zero
var exited = false;
- child.on('exit', function (code, signal) {
+ child.on('exit', function (code) {
expect(code).not.to.be(0);
exited = true;
View
4 tests/test/emit.js
@@ -1,11 +1,9 @@
var _ = require('underscore');
-var util = require('util');
var expect = require('expect.js');
describe('bootstrap/emit', function () {
var context = {};
var hooks = require('../util/hooks');
- var FIXTURE_URL = hooks.FIXTURE_URL;
beforeEach(hooks.before(context));
@@ -56,7 +54,7 @@ describe('bootstrap/emit', function () {
context.spooky.on('console', onConsole);
- context.spooky.once('run.complete', function (entry) {
+ context.spooky.once('run.complete', function () {
expect(out).to.contain('HEYO');
expect(out).to.contain('debug HEYO');
View
3  tests/test/navigation.js
@@ -1,6 +1,3 @@
-var util = require('util');
-var expect = require('expect.js');
-
describe("Spooky provides Casper's navigation functions", function () {
var context = {};
var hooks = require('../util/hooks');
View
2  tests/test/spooky.js
@@ -1,6 +1,4 @@
var _ = require('underscore');
-var Spooky = require('../../lib/spooky');
-var expect = require('expect.js');
describe('the Spooky constructor', function () {
var context = {};
View
2  tests/test/stdio.js
@@ -16,7 +16,7 @@ describe('Spooky provides a stdio transport', function () {
// expect child to exit non-zero
var exited = false;
- child.on('exit', function (code, signal) {
+ child.on('exit', function (code) {
expect(code).not.to.be(0);
exited = true;
View
2  tests/test/then.js
@@ -1,4 +1,3 @@
-var util = require('util');
var expect = require('expect.js');
describe("Spooky provides Casper's then* functions", function () {
@@ -57,6 +56,7 @@ describe("Spooky provides Casper's then* functions", function () {
context.spooky.then([{
foo: 'bar'
}, function () {
+ /* global foo */
this.echo(foo);
}]);
View
19 tests/test/wait.js
@@ -1,4 +1,3 @@
-var util = require('util');
var expect = require('expect.js');
describe("Spooky provides Casper's wait* functions", function () {
@@ -23,8 +22,6 @@ describe("Spooky provides Casper's wait* functions", function () {
it('pause step execution for a given amount of time',
function (done) {
- var out = [];
-
context.spooky.start();
context.spooky.then(function () {
@@ -53,8 +50,6 @@ describe("Spooky provides Casper's wait* functions", function () {
it('optionally executes a step on done',
function (done) {
- var out = [];
-
context.spooky.start();
context.spooky.wait(500, function () {
@@ -74,8 +69,6 @@ describe("Spooky provides Casper's wait* functions", function () {
});
it('accepts a function tuple', function (done) {
- var out = [];
-
context.spooky.start();
context.spooky.wait(500, [{
@@ -139,8 +132,6 @@ describe("Spooky provides Casper's wait* functions", function () {
it('waits until the test returns true to run the next step',
function (done) {
- var out = [];
-
context.spooky.start();
context.spooky.then(function () {
@@ -374,8 +365,6 @@ describe("Spooky provides Casper's wait* functions", function () {
it('waits until the selector matches to run the next step',
function (done) {
- var out = [];
-
context.spooky.start(FIXTURE_URL + '/1.html');
context.spooky.then(function () {
@@ -506,8 +495,6 @@ describe("Spooky provides Casper's wait* functions", function () {
it('waits until the selector does not match to run the next step',
function (done) {
- var out = [];
-
context.spooky.start(FIXTURE_URL + '/1.html');
context.spooky.then(function () {
@@ -639,8 +626,6 @@ describe("Spooky provides Casper's wait* functions", function () {
it('waits until a resource is loaded to run the next step',
function (done) {
- var out = [];
-
context.spooky.start(FIXTURE_URL + '/1.html');
context.spooky.then(function () {
@@ -777,8 +762,6 @@ describe("Spooky provides Casper's wait* functions", function () {
it('waits until the selector matches a visible element to run the next step',
function (done) {
- var out = [];
-
context.spooky.start(FIXTURE_URL + '/1.html');
context.spooky.then(function () {
@@ -918,8 +901,6 @@ describe("Spooky provides Casper's wait* functions", function () {
it('waits until the selector does not match a visible element to run the next step',
function (done) {
- var out = [];
-
context.spooky.start(FIXTURE_URL + '/1.html');
context.spooky.then(function () {
View
2  tests/test/with.js
@@ -1,8 +1,6 @@
-var util = require('util');
var expect = require('expect.js');
describe("Spooky provides Casper's with* functions", function () {
- var nop = function nop() {};
var context = {};
var hooks = require('../util/hooks');
var FIXTURE_URL = hooks.FIXTURE_URL;

0 comments on commit 6d33b14

Please sign in to comment.
Something went wrong with that request. Please try again.