Skip to content

Commit

Permalink
chore: fixed linting
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed Apr 26, 2022
1 parent bc25a87 commit 2c18890
Show file tree
Hide file tree
Showing 16 changed files with 132 additions and 147 deletions.
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"should": "^13.2.3",
"should-http": "^0.1.1",
"tinyify": "^3.0.0",
"xo": "0.47.0",
"xo": "^0.48.0",
"zuul": "^3.12.0"
},
"engines": {
Expand Down Expand Up @@ -223,7 +223,11 @@
{
"replacements": {
"res": false,
"args": false
"args": false,
"fn": false,
"err": false,
"e": false,
"i": false
}
}
],
Expand All @@ -234,7 +238,8 @@
"unicorn/no-this-assignment": "warn",
"unicorn/prefer-spread": "warn",
"unicorn/catch-error-name": "warn",
"unicorn/prefer-code-point": "warn"
"unicorn/prefer-code-point": "warn",
"node/no-unsupported-features": ["error", {"version": 8, "ignores": ["syntax"]}]
},
"globals": [
"ActiveXObject"
Expand Down
36 changes: 22 additions & 14 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,27 @@ request.getXHR = () => {

try {
return new ActiveXObject('Microsoft.XMLHTTP');
} catch {/**/}
} catch {
/**/
}

try {
return new ActiveXObject('Msxml2.XMLHTTP.6.0');
} catch {/**/}
} catch {
/**/
}

try {
return new ActiveXObject('Msxml2.XMLHTTP.3.0');
} catch {/**/}
} catch {
/**/
}

try {
return new ActiveXObject('Msxml2.XMLHTTP');
} catch {/**/}
} catch {
/**/
}

throw new Error('Browser-only version of superagent could not find XHR');
};
Expand Down Expand Up @@ -436,10 +444,10 @@ function Request(method, url) {

try {
res = new Response(self);
} catch (error_) {
} catch (err) {
error = new Error('Parser is unable to parse the response');
error.parse = true;
error.original = error_;
error.original = err;
// issue #675: return the raw response if the response parsing fails
if (self.xhr) {
// ie9 doesn't have 'response' property
Expand Down Expand Up @@ -568,15 +576,15 @@ Request.prototype.auth = function (user, pass, options) {
};
}

const encoder =
options.encoder ||
(string) => {
if (typeof btoa === 'function') {
return btoa(string);
}
const encoder = options.encoder
? options.encoder
: (string) => {
if (typeof btoa === 'function') {
return btoa(string);
}

throw new Error('Cannot use basic auth, btoa is not a function');
};
throw new Error('Cannot use basic auth, btoa is not a function');
};

return this._auth(user, pass, options, encoder);
};
Expand Down
12 changes: 6 additions & 6 deletions src/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -799,12 +799,12 @@ Request.prototype.request = function () {
}

// initiate request
const mod = this._enableHttp2
const module_ = this._enableHttp2
? exports.protocols['http2:'].setProtocol(url.protocol)
: exports.protocols[url.protocol];

// request
this.req = mod.request(options);
this.req = module_.request(options);
const { req } = this;

// set tcp no delay
Expand Down Expand Up @@ -900,8 +900,8 @@ Request.prototype.callback = function (error, res) {
error = new Error(message);
error.status = res ? res.status : undefined;
}
} catch (error_) {
error = error_;
} catch (err) {
error = err;
}
}

Expand Down Expand Up @@ -1195,15 +1195,15 @@ Request.prototype._end = function () {
let loaded = 0;

const progress = new Stream.Transform();
progress._transform = (chunk, encoding, cb) => {
progress._transform = (chunk, encoding, callback) => {
loaded += chunk.length;
this.emit('progress', {
direction: 'upload',
lengthComputable,
loaded,
total
});
cb(null, chunk);
callback(null, chunk);
};

return progress;
Expand Down
4 changes: 2 additions & 2 deletions src/node/parsers/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ module.exports = function (res, fn) {
let error;
try {
body = res.text && JSON.parse(res.text);
} catch (error_) {
error = error_;
} catch (err) {
error = err;
// issue #675: return the raw response if the response parsing fails
error.rawResponse = res.text || null;
// issue #876: return the http status code if the response parsing fails
Expand Down
14 changes: 7 additions & 7 deletions src/request-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ RequestBase.prototype._shouldRetry = function (error, res) {
if (override === true) return true;
if (override === false) return false;
// undefined falls back to defaults
} catch (error_) {
console.error(error_);
} catch (err) {
console.error(err);
}
}

Expand Down Expand Up @@ -292,8 +292,8 @@ RequestBase.prototype.then = function (resolve, reject) {
return this._fullfilledPromise.then(resolve, reject);
};

RequestBase.prototype.catch = function (cb) {
return this.then(undefined, cb);
RequestBase.prototype.catch = function (callback) {
return this.then(undefined, callback);
};

/**
Expand All @@ -305,9 +305,9 @@ RequestBase.prototype.use = function (fn) {
return this;
};

RequestBase.prototype.ok = function (cb) {
if (typeof cb !== 'function') throw new Error('Callback required');
this._okCallback = cb;
RequestBase.prototype.ok = function (callback) {
if (typeof callback !== 'function') throw new Error('Callback required');
this._okCallback = callback;
return this;
};

Expand Down
8 changes: 4 additions & 4 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,8 @@ describe('request', function () {
request_.end((error, res) => {
try {
assert(false, 'should not complete the request');
} catch (error_) {
done(error_);
} catch (err) {
done(err);
}
});

Expand Down Expand Up @@ -625,8 +625,8 @@ describe('request', function () {
request_.end((error, res) => {
try {
assert(false, 'should not complete the request');
} catch (error_) {
done(error_);
} catch (err) {
done(err);
}
});

Expand Down
2 changes: 1 addition & 1 deletion test/client/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('request', function () {

try {
var file = new File([''], 'image.jpg', { type: 'image/jpeg' });
} catch (err) {
} catch {
// Skip if file constructor not supported.
return next();
}
Expand Down
6 changes: 5 additions & 1 deletion test/node/multipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ const IS_WINDOWS = require('os').platform() === 'win32';
function read(file) {
return fs.readFileSync(file, 'utf8');
}

function getFullPath(filename) {
if (!IS_WINDOWS) {
return filename;
}

const fullPath = path.join(__dirname, '../../', filename);
return fullPath.charAt(0).toLowerCase() + fullPath.slice(1);
}
Expand Down Expand Up @@ -188,7 +190,9 @@ describe('Multipart', () => {
.end((error, res) => {
assert.ok(Boolean(error), 'Request should have failed.');
error.code.should.equal('ENOENT');
error.path.should.equal(getFullPath('test/node/fixtures/non-existent-file.ext'));
error.path.should.equal(
getFullPath('test/node/fixtures/non-existent-file.ext')
);
done();
});
});
Expand Down
16 changes: 8 additions & 8 deletions test/node/pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ before(function listen(done) {
});

describe('request pipe', () => {
const destPath = 'test/node/fixtures/tmp.json';
const destinationPath = 'test/node/fixtures/tmp.json';

after(function removeTmpfile(done) {
fs.unlink(destPath, done);
fs.unlink(destinationPath, done);
});

it('should act as a writable stream', (done) => {
Expand All @@ -68,7 +68,7 @@ describe('request pipe', () => {
});

it('end() stops piping', (done) => {
const stream = fs.createWriteStream(destPath);
const stream = fs.createWriteStream(destinationPath);
request.get(base).end((error, res) => {
try {
res.pipe(stream);
Expand All @@ -82,7 +82,7 @@ describe('request pipe', () => {
});

it('should act as a readable stream', (done) => {
const stream = fs.createWriteStream(destPath);
const stream = fs.createWriteStream(destinationPath);

let responseCalled = false;
const request_ = request.get(base);
Expand All @@ -93,7 +93,7 @@ describe('request pipe', () => {
responseCalled = true;
});
stream.on('finish', () => {
JSON.parse(fs.readFileSync(destPath, 'utf8')).should.eql({
JSON.parse(fs.readFileSync(destinationPath)).should.eql({
name: 'tobi'
});
responseCalled.should.be.true();
Expand All @@ -103,7 +103,7 @@ describe('request pipe', () => {
});

it('should follow redirects', (done) => {
const stream = fs.createWriteStream(destPath);
const stream = fs.createWriteStream(destinationPath);

let responseCalled = false;
const request_ = request.get(base + '/redirect');
Expand All @@ -114,7 +114,7 @@ describe('request pipe', () => {
responseCalled = true;
});
stream.on('finish', () => {
JSON.parse(fs.readFileSync(destPath, 'utf8')).should.eql({
JSON.parse(fs.readFileSync(destinationPath)).should.eql({
name: 'tobi'
});
responseCalled.should.be.true();
Expand All @@ -124,7 +124,7 @@ describe('request pipe', () => {
});

it('should not throw on bad redirects', (done) => {
const stream = fs.createWriteStream(destPath);
const stream = fs.createWriteStream(destinationPath);

let responseCalled = false;
let errorCalled = false;
Expand Down
4 changes: 2 additions & 2 deletions test/node/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ describe('req.query(Object)', () => {
});
});

it('query-string should be sent on pipe', function(done) {
it('query-string should be sent on pipe', function (done) {
this.timeout(15_000);
const request_ = request.put(`${base}/?name=tobi`);
const stream = fs.createReadStream('test/node/fixtures/user.json');
Expand All @@ -213,7 +213,7 @@ describe('req.query(Object)', () => {
done(err);
});

stream.on('error', function(err) {
stream.on('error', function (err) {
done(err);
});
stream.pipe(request_);
Expand Down
2 changes: 1 addition & 1 deletion test/node/toError.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ before(function listen(done) {
describe('res.toError()', () => {
it('should return an Error', (done) => {
request.get(base).end((err, res) => {
var error = res.toError();
const error = res.toError();
assert.equal(error.status, 400);
assert.equal(error.method, 'GET');
assert.equal(error.path, '/');
Expand Down
6 changes: 3 additions & 3 deletions test/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -958,9 +958,9 @@ describe('request', function () {
it('req.toJSON()', (next) => {
request.get(`${uri}/ok`).end((error, res) => {
try {
const j = (res.request || res.req).toJSON();
for (const prop of ['url', 'method', 'data', 'headers']) {
assert(j.hasOwnProperty(prop));
const index = (res.request || res.req).toJSON();
for (const property of ['url', 'method', 'data', 'headers']) {
assert(index.hasOwnProperty(property));
}

next();
Expand Down
4 changes: 2 additions & 2 deletions test/retry.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ describe('.retry(count)', function () {
request_.end((error, res) => {
try {
assert(false, 'should not complete the request');
} catch (error_) {
done(error_);
} catch (err) {
done(err);
}
});

Expand Down
4 changes: 2 additions & 2 deletions test/support/express/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ let http2Request;
let http2Res;
if (process.env.HTTP2_TEST) {
const http2 = require('http2');
const reqDecorator = require('./requestDecorator');
const requestDecorator = require('./requestDecorator');
const resDecorator = require('./responseDecorator');
http2Request = reqDecorator(
http2Request = requestDecorator(
Object.create(http2.Http2ServerRequest.prototype)
);
http2Res = resDecorator(Object.create(http2.Http2ServerResponse.prototype));
Expand Down
2 changes: 1 addition & 1 deletion test/support/express/requestDecorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ function setMethods(request) {

// support flattened arguments
if (!Array.isArray(types)) {
array = new Array(arguments.length);
array = Array.from({ length: arguments.length });
for (let i = 0; i < array.length; i++) {
array[i] = arguments[i];
}
Expand Down
Loading

0 comments on commit 2c18890

Please sign in to comment.