Use standard and prettier (#10)

* switch from custom eslint config to standard + prettier

* fix new standard eslint violations

* add editorconfig file

* auto-fix all other violations

* update lint yarn script

* remove jshint comment
This commit is contained in:
Spencer
2019-07-09 13:24:13 -07:00
committed by GitHub
parent f69840c50f
commit 7c1573fb07
119 changed files with 4506 additions and 3521 deletions

View File

@ -5,11 +5,11 @@ var XhrServer = MockHttpRequest.MockHttpServer;
var parseUrl = MockHttpRequest.prototype.parseUri;
var _ = require('lodash');
var server = new XhrServer(function (request) {
var server = new XhrServer(function(request) {
var reqDetails = {
method: request.method,
host: request.urlParts.host,
path: request.urlParts.relative
path: request.urlParts.relative,
};
var response = _.find(interceptors, reqDetails);
@ -24,36 +24,38 @@ var server = new XhrServer(function (request) {
request.receive(response.status, response.body || void 0);
} else {
throw new Error('No known match for request: ' + JSON.stringify(reqDetails));
throw new Error(
'No known match for request: ' + JSON.stringify(reqDetails)
);
}
});
server.start();
var mockNock = module.exports = function (url) {
var mockNock = (module.exports = function(url) {
var parsedUrl = parseUrl(url);
var req = {
method: 'GET',
host: parsedUrl.host,
times: 1
times: 1,
};
var modifyReq = {
get: function (path) {
get: function(path) {
req.path = path;
req.method = 'GET';
return modifyReq;
},
port: function (path) {
port: function(path) {
req.path = path;
req.method = 'POST';
return modifyReq;
},
times: function (times) {
times: function(times) {
req.times = times;
return modifyReq;
},
reply: function (status, body) {
reply: function(status, body) {
req.status = status;
req.body = body;
switch (typeof req.body) {
@ -64,20 +66,22 @@ var mockNock = module.exports = function (url) {
try {
req.body = req.body && JSON.stringify(req.body);
} catch (e) {
req.body = req.body;
// noop
}
}
interceptors.push(req);
return mockNock(url);
},
done: mockNock.done
done: mockNock.done,
};
return modifyReq;
};
});
mockNock.done = function () {
mockNock.done = function() {
if (interceptors.length) {
throw new Error('Some interceptors were not called: ' + JSON.stringify(interceptors));
throw new Error(
'Some interceptors were not called: ' + JSON.stringify(interceptors)
);
}
};

View File

@ -19,7 +19,7 @@ function MockIncommingMessage() {
this.setEncoding = sinon.stub();
this.headers = {};
this._read = function () {};
this._read = function() {};
}
util.inherits(MockIncommingMessage, Readable);

View File

@ -7,32 +7,31 @@ var util = require('util');
var MockWritableStream; // defined simply for 0.10+, in detail for older versions
var Writable = require('stream').Writable;
if (Writable) {
// nice and simple for streams 2
MockWritableStream = module.exports = function (opts) {
MockWritableStream = module.exports = function(opts) {
Writable.call(this, opts);
this._write = function () {};
this._write = function() {};
};
util.inherits(MockWritableStream, Writable);
} else {
// Node < 0.10 did not provide a usefull stream abstract
var Stream = require('stream').Stream;
module.exports = MockWritableStream = function () {
module.exports = MockWritableStream = function() {
Stream.call(this);
this.writable = true;
};
util.inherits(MockWritableStream, Stream);
MockWritableStream.prototype.write = function () {
MockWritableStream.prototype.write = function() {
if (!this.writable) {
this.emit('error', new Error('stream not writable'));
return false;
}
var cb;
if (typeof(arguments[arguments.length - 1]) === 'function') {
if (typeof arguments[arguments.length - 1] === 'function') {
cb = arguments[arguments.length - 1];
}
@ -41,7 +40,7 @@ if (Writable) {
}
};
MockWritableStream.prototype.end = function (data, encoding) {
MockWritableStream.prototype.end = function(data, encoding) {
if (typeof data === 'function') {
// no callback support
} else if (typeof encoding === 'function') {
@ -53,18 +52,20 @@ if (Writable) {
this.writable = false;
};
MockWritableStream.prototype.destroy = function (cb) {
MockWritableStream.prototype.destroy = function(cb) {
var self = this;
if (!this.writable) {
if (cb) {
process.nextTick(function () { cb(null); });
process.nextTick(function() {
cb(null);
});
}
return;
}
this.writable = false;
process.nextTick(function () {
process.nextTick(function() {
if (cb) {
cb(null);
}
@ -74,5 +75,4 @@ if (Writable) {
// There is no shutdown() for files.
MockWritableStream.prototype.destroySoon = MockWritableStream.prototype.end;
}