diff --git a/lib/github-auth.js b/lib/github-auth.js index 31679259553f5..8704cb3971142 100644 --- a/lib/github-auth.js +++ b/lib/github-auth.js @@ -122,7 +122,7 @@ function sendTokenToAllServers(token) { strictSSL: false, }; request(options, function(err, res, body) { - if (err != null) { return reject('Posting the GitHub user token failed: ' + err.stack); } + if (err != null) { return reject(err); } resolve(); }); }); diff --git a/lib/github-provider.js b/lib/github-provider.js index 678a1becb8ce8..e9aea88768f87 100644 --- a/lib/github-provider.js +++ b/lib/github-provider.js @@ -17,7 +17,7 @@ const { // GitHub commits since integration. function mapGithubCommitsSince(camp, githubApiUrl, githubAuth) { - camp.route(/^\/github\/commits-since\/([^\/]+)\/([^\/]+)\/([^\/]+)\.(svg|png|gif|jpg|json)$/, + camp.route(/^\/github\/commits-since\/([^/]+)\/([^/]+)\/([^/]+)\.(svg|png|gif|jpg|json)$/, cache(function (data, match, sendBadge, request) { const user = match[1]; // eg, SubtitleEdit const repo = match[2]; // eg, subtitleedit @@ -62,17 +62,14 @@ function mapGithubCommitsSince(camp, githubApiUrl, githubAuth) { try { const data = JSON.parse(buffer); setCommitsSinceBadge(user, repo, data.tag_name); - return; } catch (e) { badgeData.text[1] = 'invalid'; sendBadge(format, badgeData); - return; } }); } else { setCommitsSinceBadge(user, repo, version); } - })); } diff --git a/lib/lru-cache.js b/lib/lru-cache.js index 1ef4262c0a965..6a5959521ee59 100644 --- a/lib/lru-cache.js +++ b/lib/lru-cache.js @@ -126,7 +126,7 @@ function getHeapSize() { } } function computeHeapSize() { - return heapSize = process.memoryUsage().heapTotal; + return (heapSize = process.memoryUsage().heapTotal); } module.exports = Cache; diff --git a/lib/nexus-version.js b/lib/nexus-version.js index efbe67e44e49a..3f3a51d306813 100644 --- a/lib/nexus-version.js +++ b/lib/nexus-version.js @@ -1,12 +1,8 @@ 'use strict'; function isSnapshotVersion(version) { - const pattern = /(\d+\.)*\d\-SNAPSHOT/; - if (version) { - return version.match(pattern); - } else { - return false; - } + const pattern = /(\d+\.)*\d-SNAPSHOT/; + return version && version.match(pattern); } module.exports = { diff --git a/lib/npm-provider.js b/lib/npm-provider.js index b377b91a9caec..3d85b2981101d 100644 --- a/lib/npm-provider.js +++ b/lib/npm-provider.js @@ -6,7 +6,7 @@ const { metric } = require('./text-formatters'); // npm downloads count function mapNpmDownloads(camp, urlComponent, apiUriComponent) { - camp.route(new RegExp('^\/npm\/' + urlComponent + '\/(.*)\.(svg|png|gif|jpg|json)$'), + camp.route(new RegExp('^/npm/' + urlComponent + '/(.*)\\.(svg|png|gif|jpg|json)$'), cache(function(data, match, sendBadge, request) { const pkg = encodeURIComponent(match[1]); // eg, "express" or "@user/express" const format = match[2]; diff --git a/lib/php-version.js b/lib/php-version.js index c1f45ba1a02ff..3f00b0199f806 100644 --- a/lib/php-version.js +++ b/lib/php-version.js @@ -160,7 +160,7 @@ function numberedVersionData(version) { // Try to convert to a list of numbers. function toNum (s) { let n = +s; - if (n !== n) { // If n is NaN… + if (Number.isNaN(n)) { n = 0xffffffff; } return n; diff --git a/lib/result-sender.js b/lib/result-sender.js index 959a7f603db4f..4ea3a88caec74 100644 --- a/lib/result-sender.js +++ b/lib/result-sender.js @@ -1,15 +1,22 @@ 'use strict'; +const stream = require('stream'); const log = require('./log'); const svg2img = require('./svg-to-img'); +function streamFromString(str) { + const newStream = new stream.Readable(); + newStream._read = () => { newStream.push(str); newStream.push(null); }; + return newStream; +} + function makeSend(format, askres, end) { if (format === 'svg') { - return function(res) { sendSVG(res, askres, end); }; + return res => sendSVG(res, askres, end); } else if (format === 'json') { - return function(res) { sendJSON(res, askres, end); }; + return res => sendJSON(res, askres, end); } else { - return function(res) { sendOther(format, res, askres, end); }; + return res => sendOther(format, res, askres, end); } } @@ -37,13 +44,6 @@ function sendJSON(res, askres, end) { end(null, {template: streamFromString(res)}); } -const stream = require('stream'); -function streamFromString(str) { - const newStream = new stream.Readable(); - newStream._read = function() { newStream.push(str); newStream.push(null); }; - return newStream; -} - module.exports = { makeSend }; diff --git a/lib/suggest.js b/lib/suggest.js index 244071e589ea0..40190bba420a1 100644 --- a/lib/suggest.js +++ b/lib/suggest.js @@ -137,7 +137,7 @@ function githubLicense (user, repo) { let licenseFilename; // Crawl each file in the root directory for (let i = 0; i < treeArray.length; i++) { - if (treeArray[i].type != 'blob') { + if (treeArray[i].type !== 'blob') { continue; } if (treeArray[i].path.match(/(LICENSE|COPYING|COPYRIGHT).*/i)) { @@ -179,13 +179,13 @@ function githubLicense (user, repo) { resolve(null); return; } - } catch(e) { reject(e); return; } + } catch(e) { reject(e); } }); - } catch(e) { reject(e); return; } + } catch(e) { reject(e); } }); - } catch(e) { reject(e); return; } + } catch(e) { reject(e); } }); - } catch(e) { reject(e); return; } + } catch(e) { reject(e); } }); }); } diff --git a/lib/version.js b/lib/version.js index 0500af97e71fd..1f442c1504e31 100644 --- a/lib/version.js +++ b/lib/version.js @@ -62,8 +62,8 @@ function latestDottedVersion(versions) { // Take string versions. // -1 if v1 < v2, 1 if v1 > v2, 0 otherwise. function compareDottedVersion(v1, v2) { - const parts1 = /([0-9\.]+)(.*)$/.exec(v1); - const parts2 = /([0-9\.]+)(.*)$/.exec(v2); + const parts1 = /([0-9.]+)(.*)$/.exec(v1); + const parts2 = /([0-9.]+)(.*)$/.exec(v2); if (parts1 != null && parts2 != null) { const numbers1 = parts1[1]; const numbers2 = parts2[1]; diff --git a/service-tests/bower.js b/service-tests/bower.js index c7b1a72bdb553..042d6b13fd09c 100644 --- a/service-tests/bower.js +++ b/service-tests/bower.js @@ -38,14 +38,14 @@ t.create('pre version. eg. bower|v0.2.5-alpha-rc-pre') .get('/vpre/bootstrap.json') .expectJSONTypes(Joi.object().keys({ name: Joi.equal('bower'), - value: Joi.string().regex(/^v\d+(\.\d+)?(\.\d+)?(\-?\w)+?$/) + value: Joi.string().regex(/^v\d+(\.\d+)?(\.\d+)?(-?\w)+?$/) })); t.create('custom label for pre version. eg. pre verison|v0.2.5-alpha-rc-pre') .get('/vpre/bootstrap.json?label="pre verison"') .expectJSONTypes(Joi.object().keys({ name: Joi.equal('pre verison'), - value: Joi.string().regex(/^v\d+(\.\d+)?(\.\d+)?(\-?\w)+?$/) + value: Joi.string().regex(/^v\d+(\.\d+)?(\.\d+)?(-?\w)+?$/) })); diff --git a/service-tests/codecov.js b/service-tests/codecov.js index 01e9d32d6d6f7..99d49a6ebd4dc 100644 --- a/service-tests/codecov.js +++ b/service-tests/codecov.js @@ -10,12 +10,12 @@ t.create('gets coverage status') .get('/c/github/codecov/example-python.json') .expectJSONTypes(Joi.object().keys({ name: 'coverage', - value: Joi.string().regex(/^[0-9]+\%$/), + value: Joi.string().regex(/^[0-9]+%$/), })); t.create('gets coverate status for branch') .get('/c/github/codecov/example-python/master.json') .expectJSONTypes({ name: 'coverage', - value: Joi.string().regex(/^[0-9]+\%$/), + value: Joi.string().regex(/^[0-9]+%$/), });