Skip to content

Commit

Permalink
fix: fixed linting, fixed deprecation warning in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
niftylettuce committed Dec 1, 2019
1 parent 8dc8b91 commit 7d70a75
Show file tree
Hide file tree
Showing 27 changed files with 11,913 additions and 342 deletions.
3 changes: 2 additions & 1 deletion .dist.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"browsers": [ "> 1%", "last 2 versions", "ie 9" ]
}
}]
]
],
"sourceMaps": "inline"
}
3 changes: 2 additions & 1 deletion .dist.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"no-unused-vars": "off",
"no-useless-escape": "off",
"no-cond-assign": "off",
"no-redeclare": "off"
"no-redeclare": "off",
"node/no-exports-assign": "off"
},
"globals": {
"regeneratorRuntime": "writable"
Expand Down
3 changes: 2 additions & 1 deletion .lib.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"browsers": [ "> 1%", "last 2 versions", "ie 9" ]
}
}]
]
],
"sourceMaps": "inline"
}
3 changes: 2 additions & 1 deletion .lib.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"no-empty": "off",
"node/no-unsupported-features/node-builtins": "off",
"no-func-assign": "off",
"no-global-assign": ["error", {"exceptions": ["exports"]}]
"no-global-assign": ["error", {"exceptions": ["exports"]}],
"node/no-exports-assign": "off"
},
"overrides": [
{
Expand Down
54 changes: 27 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,50 +26,50 @@
"component-emitter": "^1.3.0",
"cookiejar": "^2.1.2",
"debug": "^4.1.1",
"fast-safe-stringify": "^2.0.6",
"form-data": "^2.3.3",
"fast-safe-stringify": "^2.0.7",
"form-data": "^3.0.0",
"formidable": "^1.2.1",
"methods": "^1.1.2",
"mime": "^2.4.4",
"qs": "^6.7.0",
"qs": "^6.9.1",
"readable-stream": "^3.4.0",
"semver": "^6.1.1"
"semver": "^6.3.0"
},
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.5",
"@babel/preset-env": "^7.4.5",
"@commitlint/cli": "^8.0.0",
"@commitlint/config-conventional": "^8.0.0",
"Base64": "^1.0.2",
"@babel/cli": "^7.7.4",
"@babel/core": "^7.7.4",
"@babel/preset-env": "^7.7.4",
"@commitlint/cli": "^8.2.0",
"@commitlint/config-conventional": "^8.2.0",
"Base64": "^1.1.0",
"babelify": "^10.0.0",
"basic-auth-connect": "^1.0.0",
"body-parser": "^1.19.0",
"browserify": "^16.2.3",
"codecov": "^3.5.0",
"browserify": "^16.5.0",
"codecov": "^3.6.1",
"cookie-parser": "^1.4.4",
"cross-env": "^5.2.0",
"eslint": "^5.16.0",
"cross-env": "^6.0.3",
"eslint": "^6.7.2",
"eslint-config-xo-lass": "^1.0.3",
"eslint-plugin-compat": "^3.1.1",
"eslint-plugin-node": "^9.1.0",
"eslint-plugin-compat": "^3.3.0",
"eslint-plugin-node": "^10.0.0",
"express": "^4.17.1",
"express-session": "^1.16.2",
"express-session": "^1.17.0",
"fixpack": "^2.3.1",
"husky": "^2.4.1",
"lint-staged": "^8.2.0",
"marked": "^0.6.2",
"husky": "^3.1.0",
"lint-staged": "^9.5.0",
"marked": "^0.7.0",
"mocha": "3.5.3",
"multer": "^1.4.1",
"multer": "^1.4.2",
"nyc": "^14.1.1",
"remark-cli": "^6.0.1",
"remark-preset-github": "^0.0.13",
"rimraf": "^2.6.3",
"remark-cli": "^7.0.1",
"remark-preset-github": "^0.0.16",
"rimraf": "^3.0.0",
"should": "^13.2.3",
"should-http": "^0.1.1",
"tinyify": "^2.5.1",
"uglify-js": "^3.6.0",
"xo": "0.24.0",
"tinyify": "^2.5.2",
"uglify-js": "^3.7.1",
"xo": "0.25.3",
"zuul": "^3.12.0"
},
"engines": {
Expand Down
20 changes: 10 additions & 10 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,19 @@ request.getXHR = () => {

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

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

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

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

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

try {
res = new Response(self);
} catch (err2) {
} catch (err_) {
err = new Error('Parser is unable to parse the response');
err.parse = true;
err.original = err2;
err.original = err_;
// issue #675: return the raw response if the response parsing fails
if (self.xhr) {
// ie9 doesn't have 'response' property
Expand All @@ -466,8 +466,8 @@ function Request(method, url) {
if (!self._isResponseOK(res)) {
new_err = new Error(res.statusText || 'Unsuccessful HTTP response');
}
} catch (err2) {
new_err = err2; // ok() callback can throw
} catch (err_) {
new_err = err_; // ok() callback can throw
}

// #1000 don't catch errors from the callback to avoid double calling it
Expand Down Expand Up @@ -787,7 +787,7 @@ Request.prototype._end = function() {
let status;
try {
status = xhr.status;
} catch (err) {
} catch {
status = 0;
}

Expand Down Expand Up @@ -822,7 +822,7 @@ Request.prototype._end = function() {
handleProgress.bind(null, 'upload')
);
}
} catch (err) {
} catch {
// Accessing xhr.upload fails in IE from a web worker, so just pretend it doesn't exist.
// Reported here:
// https://connect.microsoft.com/IE/feedback/details/837245/xmlhttprequest-upload-throws-invalid-argument-when-used-from-web-worker-context
Expand Down
6 changes: 2 additions & 4 deletions src/node/http2wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ Request.prototype.getFrame = function() {
Request.prototype.mapToHttpHeader = function(headers) {
const keys = Object.keys(headers);
const http2Headers = {};
for (let i = 0; i < keys.length; i++) {
let key = keys[i];
for (let key of keys) {
let value = headers[key];
key = key.toLowerCase();
switch (key) {
Expand All @@ -147,8 +146,7 @@ Request.prototype.mapToHttpHeader = function(headers) {
Request.prototype.mapToHttp2Header = function(headers) {
const keys = Object.keys(headers);
const http2Headers = {};
for (let i = 0; i < keys.length; i++) {
let key = keys[i];
for (let key of keys) {
let value = headers[key];
key = key.toLowerCase();
switch (key) {
Expand Down
20 changes: 8 additions & 12 deletions src/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ Request.prototype.agent = function(agent) {
Request.prototype.type = function(type) {
return this.set(
'Content-Type',
type.indexOf('/') === -1 ? mime.getType(type) : type
type.includes('/') ? type : mime.getType(type)
);
};

Expand All @@ -353,10 +353,7 @@ Request.prototype.type = function(type) {
*/

Request.prototype.accept = function(type) {
return this.set(
'Accept',
type.indexOf('/') === -1 ? mime.getType(type) : type
);
return this.set('Accept', type.includes('/') ? type : mime.getType(type));
};

/**
Expand Down Expand Up @@ -684,11 +681,11 @@ Request.prototype.request = function() {
// Note: this'll only find backticks entered in req.query(String)
// calls, because qs.stringify unconditionally encodes backticks.
let queryStringBackticks;
if (url.indexOf('`') > -1) {
if (url.includes('`')) {
const queryStartIndex = url.indexOf('?');

if (queryStartIndex !== -1) {
const queryString = url.substr(queryStartIndex + 1);
const queryString = url.slice(queryStartIndex + 1);
queryStringBackticks = queryString.match(/`|%60/g);
}
}
Expand Down Expand Up @@ -867,8 +864,8 @@ Request.prototype.callback = function(err, res) {
err = new Error(msg);
err.status = res ? res.status : undefined;
}
} catch (err2) {
err = err2;
} catch (err_) {
err = err_;
}
}

Expand Down Expand Up @@ -1245,7 +1242,6 @@ Request.prototype._shouldUnzip = res => {
return /^\s*(?:deflate|gzip)\s*$/.test(res.headers['content-encoding']);
};

// eslint-disable-next-line valid-jsdoc
/**
* Overrides DNS for selected hostnames. Takes object mapping hostnames to IP addresses.
*
Expand Down Expand Up @@ -1277,7 +1273,7 @@ Request.prototype.trustLocalhost = function(toggle) {
};

// generate HTTP verb methods
if (methods.indexOf('del') === -1) {
if (!methods.includes('del')) {
// create a copy so we don't cause conflicts with
// other packages using the methods package and
// npm 3.x
Expand Down Expand Up @@ -1355,5 +1351,5 @@ function isJSON(mime) {
*/

function isRedirect(code) {
return [301, 302, 303, 305, 307, 308].indexOf(code) !== -1;
return [301, 302, 303, 305, 307, 308].includes(code);
}
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 err;
try {
body = res.text && JSON.parse(res.text);
} catch (err2) {
err = err2;
} catch (err_) {
err = err_;
// issue #675: return the raw response if the response parsing fails
err.rawResponse = res.text || null;
// issue #876: return the http status code if the response parsing fails
Expand Down
13 changes: 6 additions & 7 deletions src/request-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,14 @@ RequestBase.prototype._shouldRetry = function(err, res) {
if (override === true) return true;
if (override === false) return false;
// undefined falls back to defaults
} catch (err2) {
console.error(err2);
} catch (err_) {
console.error(err_);
}
}

if (res && res.status && res.status >= 500 && res.status !== 501) return true;
if (err) {
if (err.code && ERROR_CODES.indexOf(err.code) !== -1) return true;
if (err.code && ERROR_CODES.includes(err.code)) return true;
// Superagent timeout
if (err.timeout && err.code === 'ECONNABORTED') return true;
if (err.crossDomain) return true;
Expand Down Expand Up @@ -357,7 +357,6 @@ RequestBase.prototype.set = function(field, val) {
return this;
};

// eslint-disable-next-line valid-jsdoc
/**
* Remove header `field`.
* Case-insensitive.
Expand Down Expand Up @@ -674,22 +673,22 @@ RequestBase.prototype.sortQuery = function(sort) {
RequestBase.prototype._finalizeQueryString = function() {
const query = this._query.join('&');
if (query) {
this.url += (this.url.indexOf('?') >= 0 ? '&' : '?') + query;
this.url += (this.url.includes('?') ? '&' : '?') + query;
}

this._query.length = 0; // Makes the call idempotent

if (this._sort) {
const index = this.url.indexOf('?');
if (index >= 0) {
const queryArr = this.url.substring(index + 1).split('&');
const queryArr = this.url.slice(index + 1).split('&');
if (typeof this._sort === 'function') {
queryArr.sort(this._sort);
} else {
queryArr.sort();
}

this.url = this.url.substring(0, index) + '?' + queryArr.join('&');
this.url = this.url.slice(0, index) + '?' + queryArr.join('&');
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/response-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ ResponseBase.prototype._setHeaderProperties = function(header) {
if (header.link) {
this.links = utils.parseLinks(header.link);
}
} catch (err) {
} catch {
// ignore
}
};
Expand Down
Loading

0 comments on commit 7d70a75

Please sign in to comment.