From b80b90229ffe49f9dd3f05ac39cb8da193f0bc12 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Mon, 12 Jun 2023 15:27:12 +0100 Subject: [PATCH] Added consistent linting pattern to all packages refs: https://github.com/TryGhost/Toolbox/issues/188 - some of our older packages used a pattern for linting which missed using test config for linting tests - we need this to be consistent so that we can add more eslint rules for testing - two packages also didn't use the lib pattern, which made the lint pattern error - so this was fixed as well --- ghost/adapter-manager/package.json | 4 +- ghost/bootstrap-socket/package.json | 4 +- ghost/constants/index.js | 19 +- ghost/constants/lib/constants.js | 18 ++ ghost/constants/package.json | 4 +- .../package.json | 4 +- ghost/domain-events/package.json | 4 +- .../package.json | 4 +- ghost/email-analytics-service/package.json | 4 +- ghost/express-dynamic-redirects/package.json | 4 +- ghost/job-manager/package.json | 4 +- ghost/magic-link/package.json | 4 +- ghost/member-events/package.json | 4 +- ghost/members-api/package.json | 4 +- ghost/members-csv/package.json | 4 +- ghost/members-events-service/package.json | 4 +- ghost/members-importer/package.json | 4 +- ghost/members-ssr/package.json | 4 +- ghost/minifier/package.json | 4 +- ghost/mw-error-handler/package.json | 4 +- ghost/mw-session-from-token/package.json | 4 +- ghost/mw-update-user-last-seen/package.json | 4 +- ghost/mw-vhost/index.js | 172 +----------------- ghost/mw-vhost/lib/vhost.js | 171 +++++++++++++++++ ghost/mw-vhost/package.json | 4 +- ghost/oembed-service/test/hello.test.js | 2 +- ghost/offers/package.json | 4 +- ghost/package-json/package.json | 4 +- ghost/payments/package.json | 4 +- ghost/security/package.json | 4 +- ghost/session-service/package.json | 4 +- ghost/settings-path-manager/package.json | 4 +- ghost/stripe/package.json | 4 +- ghost/update-check-service/package.json | 4 +- ghost/verification-trigger/package.json | 4 +- 35 files changed, 282 insertions(+), 220 deletions(-) create mode 100644 ghost/constants/lib/constants.js create mode 100644 ghost/mw-vhost/lib/vhost.js diff --git a/ghost/adapter-manager/package.json b/ghost/adapter-manager/package.json index a9b2d18f7f..84679c5b36 100644 --- a/ghost/adapter-manager/package.json +++ b/ghost/adapter-manager/package.json @@ -9,7 +9,9 @@ "dev": "echo \"Implement me!\"", "test:unit": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura mocha './test/**/*.test.js'", "test": "yarn test:unit", - "lint": "eslint . --ext .js --cache" + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" }, "files": [ "index.js", diff --git a/ghost/bootstrap-socket/package.json b/ghost/bootstrap-socket/package.json index f4ec6f29d4..a5379df032 100644 --- a/ghost/bootstrap-socket/package.json +++ b/ghost/bootstrap-socket/package.json @@ -9,7 +9,9 @@ "dev": "echo \"Implement me!\"", "test:unit": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura mocha './test/**/*.test.js'", "test": "yarn test:unit", - "lint": "eslint . --ext .js --cache" + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" }, "files": [ "index.js", diff --git a/ghost/constants/index.js b/ghost/constants/index.js index 411ba55783..1d0e2d9213 100644 --- a/ghost/constants/index.js +++ b/ghost/constants/index.js @@ -1,18 +1 @@ -module.exports = { - ONE_HOUR_S: 3600, - ONE_DAY_S: 86400, - ONE_WEEK_S: 604800, - ONE_MONTH_S: 2628000, - SIX_MONTH_S: 15768000, - ONE_YEAR_S: 31536000, - FIVE_MINUTES_MS: 300000, - ONE_HOUR_MS: 3600000, - ONE_DAY_MS: 86400000, - ONE_WEEK_MS: 604800000, - ONE_MONTH_MS: 2628000000, - SIX_MONTH_MS: 15768000000, - ONE_YEAR_MS: 31536000000, - STATIC_IMAGES_URL_PREFIX: 'content/images', - STATIC_MEDIA_URL_PREFIX: 'content/media', - STATIC_FILES_URL_PREFIX: 'content/files' -}; +module.exports = require('./lib/constants'); diff --git a/ghost/constants/lib/constants.js b/ghost/constants/lib/constants.js new file mode 100644 index 0000000000..411ba55783 --- /dev/null +++ b/ghost/constants/lib/constants.js @@ -0,0 +1,18 @@ +module.exports = { + ONE_HOUR_S: 3600, + ONE_DAY_S: 86400, + ONE_WEEK_S: 604800, + ONE_MONTH_S: 2628000, + SIX_MONTH_S: 15768000, + ONE_YEAR_S: 31536000, + FIVE_MINUTES_MS: 300000, + ONE_HOUR_MS: 3600000, + ONE_DAY_MS: 86400000, + ONE_WEEK_MS: 604800000, + ONE_MONTH_MS: 2628000000, + SIX_MONTH_MS: 15768000000, + ONE_YEAR_MS: 31536000000, + STATIC_IMAGES_URL_PREFIX: 'content/images', + STATIC_MEDIA_URL_PREFIX: 'content/media', + STATIC_FILES_URL_PREFIX: 'content/files' +}; diff --git a/ghost/constants/package.json b/ghost/constants/package.json index db9d0238a4..39daff4cd1 100644 --- a/ghost/constants/package.json +++ b/ghost/constants/package.json @@ -9,7 +9,9 @@ "dev": "echo \"Implement me!\"", "test:unit": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura mocha './test/**/*.test.js'", "test": "yarn test:unit", - "lint": "eslint . --ext .js --cache" + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" }, "files": [ "index.js", diff --git a/ghost/custom-theme-settings-service/package.json b/ghost/custom-theme-settings-service/package.json index f2fa8498bb..4fcfe1133c 100644 --- a/ghost/custom-theme-settings-service/package.json +++ b/ghost/custom-theme-settings-service/package.json @@ -9,7 +9,9 @@ "dev": "echo \"Implement me!\"", "test:unit": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura --check-coverage mocha './test/**/*.test.js'", "test": "yarn test:unit", - "lint": "eslint . --ext .js --cache" + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" }, "files": [ "index.js", diff --git a/ghost/domain-events/package.json b/ghost/domain-events/package.json index 459d1d7be3..9464446ef1 100644 --- a/ghost/domain-events/package.json +++ b/ghost/domain-events/package.json @@ -10,7 +10,9 @@ "dev": "echo \"Implement me!\"", "test:unit": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura --check-coverage --100 mocha './test/**/*.test.js'", "test": "yarn test:unit", - "lint": "eslint . --ext .js --cache" + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" }, "files": [ "index.js", diff --git a/ghost/email-analytics-provider-mailgun/package.json b/ghost/email-analytics-provider-mailgun/package.json index bfba539556..5849759f57 100644 --- a/ghost/email-analytics-provider-mailgun/package.json +++ b/ghost/email-analytics-provider-mailgun/package.json @@ -9,7 +9,9 @@ "dev": "echo \"Implement me!\"", "test:unit": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura --check-coverage --100 mocha './test/**/*.test.js'", "test": "yarn test:unit", - "lint": "eslint . --ext .js --cache" + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" }, "files": [ "index.js", diff --git a/ghost/email-analytics-service/package.json b/ghost/email-analytics-service/package.json index 57eef94bb8..bb8ec6fe6b 100644 --- a/ghost/email-analytics-service/package.json +++ b/ghost/email-analytics-service/package.json @@ -9,7 +9,9 @@ "dev": "echo \"Implement me!\"", "test:unit": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura mocha './test/**/*.test.js'", "test": "yarn test:unit", - "lint": "eslint . --ext .js --cache" + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" }, "files": [ "index.js", diff --git a/ghost/express-dynamic-redirects/package.json b/ghost/express-dynamic-redirects/package.json index 4069900731..e31f826757 100644 --- a/ghost/express-dynamic-redirects/package.json +++ b/ghost/express-dynamic-redirects/package.json @@ -9,7 +9,9 @@ "dev": "echo \"Implement me!\"", "test:unit": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura --check-coverage mocha './test/**/*.test.js'", "test": "yarn test:unit", - "lint": "eslint . --ext .js --cache" + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" }, "files": [ "index.js", diff --git a/ghost/job-manager/package.json b/ghost/job-manager/package.json index 66bdd2d38a..64e5e46ac3 100644 --- a/ghost/job-manager/package.json +++ b/ghost/job-manager/package.json @@ -9,7 +9,9 @@ "dev": "echo \"Implement me!\"", "test:unit": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura mocha './test/**/*.test.js'", "test": "yarn test:unit", - "lint": "eslint . --ext .js --cache" + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" }, "files": [ "index.js", diff --git a/ghost/magic-link/package.json b/ghost/magic-link/package.json index 04d3dba753..0adf76c4a4 100644 --- a/ghost/magic-link/package.json +++ b/ghost/magic-link/package.json @@ -9,7 +9,9 @@ "dev": "echo \"Implement me!\"", "test:unit": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura mocha './test/**/*.test.js'", "test": "yarn test:unit", - "lint": "eslint . --ext .js --cache" + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" }, "files": [ "index.js", diff --git a/ghost/member-events/package.json b/ghost/member-events/package.json index 3b9ef32ca9..5853b9145d 100644 --- a/ghost/member-events/package.json +++ b/ghost/member-events/package.json @@ -9,7 +9,9 @@ "dev": "echo \"Implement me!\"", "test:unit": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura mocha './test/**/*.test.js'", "test": "yarn test:unit", - "lint": "eslint . --ext .js --cache" + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" }, "files": [ "index.js", diff --git a/ghost/members-api/package.json b/ghost/members-api/package.json index a839561732..815b716a7a 100644 --- a/ghost/members-api/package.json +++ b/ghost/members-api/package.json @@ -9,7 +9,9 @@ "dev": "echo \"Implement me!\"", "test:unit": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura mocha --reporter dot './test/**/*.test.js'", "test": "yarn test:unit", - "lint": "eslint . --ext .js --cache" + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" }, "files": [ "index.js", diff --git a/ghost/members-csv/package.json b/ghost/members-csv/package.json index a6a836fe93..2a7587760a 100644 --- a/ghost/members-csv/package.json +++ b/ghost/members-csv/package.json @@ -9,7 +9,9 @@ "dev": "echo \"Implement me!\"", "test:unit": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura mocha './test/**/*.test.js'", "test": "yarn test:unit", - "lint": "eslint . --ext .js --cache" + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" }, "files": [ "index.js", diff --git a/ghost/members-events-service/package.json b/ghost/members-events-service/package.json index bc67f86108..e9c6618361 100644 --- a/ghost/members-events-service/package.json +++ b/ghost/members-events-service/package.json @@ -9,7 +9,9 @@ "dev": "echo \"Implement me!\"", "test:unit": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura --check-coverage mocha './test/**/*.test.js'", "test": "yarn test:unit", - "lint": "eslint . --ext .js --cache" + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" }, "files": [ "index.js", diff --git a/ghost/members-importer/package.json b/ghost/members-importer/package.json index d0fb3aa62d..ca72b0232e 100644 --- a/ghost/members-importer/package.json +++ b/ghost/members-importer/package.json @@ -9,7 +9,9 @@ "dev": "echo \"Implement me!\"", "test:unit": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura mocha './test/**/*.test.js'", "test": "yarn test:unit", - "lint": "eslint . --ext .js --cache" + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" }, "files": [ "index.js", diff --git a/ghost/members-ssr/package.json b/ghost/members-ssr/package.json index 2cd0b4d191..7114ba32bc 100644 --- a/ghost/members-ssr/package.json +++ b/ghost/members-ssr/package.json @@ -9,7 +9,9 @@ "dev": "echo \"Implement me!\"", "test:unit": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura mocha './test/**/*.test.js'", "test": "yarn test:unit", - "lint": "eslint . --ext .js --cache" + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" }, "files": [ "index.js", diff --git a/ghost/minifier/package.json b/ghost/minifier/package.json index e5fe6ecb6f..c44528690c 100644 --- a/ghost/minifier/package.json +++ b/ghost/minifier/package.json @@ -9,7 +9,9 @@ "dev": "echo \"Implement me!\"", "test:unit": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura mocha './test/**/*.test.js'", "test": "yarn test:unit", - "lint": "eslint . --ext .js --cache" + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" }, "files": [ "index.js", diff --git a/ghost/mw-error-handler/package.json b/ghost/mw-error-handler/package.json index 79ab76060b..eb59e53271 100644 --- a/ghost/mw-error-handler/package.json +++ b/ghost/mw-error-handler/package.json @@ -9,7 +9,9 @@ "dev": "echo \"Implement me!\"", "test:unit": "NODE_ENV=testing c8 --all --check-coverage --100 --reporter text --reporter cobertura mocha './test/**/*.test.js'", "test": "yarn test:unit", - "lint": "eslint . --ext .js --cache" + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" }, "files": [ "index.js", diff --git a/ghost/mw-session-from-token/package.json b/ghost/mw-session-from-token/package.json index d470734fc2..ee9cc63712 100644 --- a/ghost/mw-session-from-token/package.json +++ b/ghost/mw-session-from-token/package.json @@ -9,7 +9,9 @@ "dev": "echo \"Implement me!\"", "test:unit": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura mocha './test/**/*.test.js'", "test": "yarn test:unit", - "lint": "eslint . --ext .js --cache" + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" }, "files": [ "index.js", diff --git a/ghost/mw-update-user-last-seen/package.json b/ghost/mw-update-user-last-seen/package.json index 29ffc3733f..7089e0526f 100644 --- a/ghost/mw-update-user-last-seen/package.json +++ b/ghost/mw-update-user-last-seen/package.json @@ -9,7 +9,9 @@ "dev": "echo \"Implement me!\"", "test:unit": "NODE_ENV=testing c8 --all --check-coverage --reporter text --reporter cobertura mocha './test/**/*.test.js'", "test": "yarn test:unit", - "lint": "eslint . --ext .js --cache" + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" }, "files": [ "index.js", diff --git a/ghost/mw-vhost/index.js b/ghost/mw-vhost/index.js index 546aed7707..d23fc9054c 100644 --- a/ghost/mw-vhost/index.js +++ b/ghost/mw-vhost/index.js @@ -1,171 +1 @@ -// This a fork of expressjs/vhost with trust proxy support -/* eslint-disable */ - -/*! - * vhost - * Copyright(c) 2014 Jonathan Ong - * Copyright(c) 2014-2015 Douglas Christopher Wilson - * MIT Licensed - */ - - -'use strict'; - -/** - * Module exports. - * @public - */ - -module.exports = vhost; - -/** - * Module variables. - * @private - */ - -var ASTERISK_REGEXP = /\*/g; -var ASTERISK_REPLACE = '([^.]+)'; -var END_ANCHORED_REGEXP = /(?:^|[^\\])(?:\\\\)*\$$/; -var ESCAPE_REGEXP = /([.+?^=!:${}()|[\]/\\])/g; -var ESCAPE_REPLACE = '\\$1'; - -/** - * Create a vhost middleware. - * - * @param {string|RegExp} hostname - * @param {function} handle - * @return {Function} - * @public - */ - -function vhost(hostname, handle) { - if (!hostname) { - throw new TypeError('argument hostname is required'); - } - - if (!handle) { - throw new TypeError('argument handle is required'); - } - - if (typeof handle !== 'function') { - throw new TypeError('argument handle must be a function'); - } - - // create regular expression for hostname - var regexp = hostregexp(hostname); - - return function vhost(req, res, next) { - var vhostdata = vhostof(req, regexp); - - if (!vhostdata) { - return next(); - } - - // populate - req.vhost = vhostdata; - - // handle - handle(req, res, next); - }; -} - -/** - * Get hostname of request. - * - * @param {object} req - * @return {string} - * @private - */ - -function hostnameof(req) { - var host = - req.hostname || // express v4 - req.host || // express v3 - req.headers.host; // http - - if (!host) { - return; - } - - var offset = host[0] === '[' - ? host.indexOf(']') + 1 - : 0; - var index = host.indexOf(':', offset); - - return index !== -1 - ? host.substring(0, index) - : host; -} - -/** - * Determine if object is RegExp. - * - * @param {object} val - * @return {boolean} - * @private - */ - -function isregexp(val) { - return Object.prototype.toString.call(val) === '[object RegExp]'; -} - -/** - * Generate RegExp for given hostname value. - * - * @param {string|RegExp} val - * @private - */ - -function hostregexp(val) { - var source = !isregexp(val) - ? String(val).replace(ESCAPE_REGEXP, ESCAPE_REPLACE).replace(ASTERISK_REGEXP, ASTERISK_REPLACE) - : val.source; - - // force leading anchor matching - if (source[0] !== '^') { - source = '^' + source; - } - - // force trailing anchor matching - if (!END_ANCHORED_REGEXP.test(source)) { - source += '$'; - } - - return new RegExp(source, 'i'); -} - -/** - * Get the vhost data of the request for RegExp - * - * @param {object} req - * @param {RegExp} regexp - * @return {object} - * @private - */ - -function vhostof(req, regexp) { - var host = req.headers.host; - var hostname = hostnameof(req); - - if (!hostname) { - return; - } - - var match = regexp.exec(hostname); - - if (!match) { - return; - } - - var obj = Object.create(null); - - obj.host = host; - obj.hostname = hostname; - obj.length = match.length - 1; - - for (var i = 1; i < match.length; i++) { - obj[i - 1] = match[i]; - } - - return obj; -} +module.exports = require('./lib/vhost'); diff --git a/ghost/mw-vhost/lib/vhost.js b/ghost/mw-vhost/lib/vhost.js new file mode 100644 index 0000000000..546aed7707 --- /dev/null +++ b/ghost/mw-vhost/lib/vhost.js @@ -0,0 +1,171 @@ +// This a fork of expressjs/vhost with trust proxy support +/* eslint-disable */ + +/*! + * vhost + * Copyright(c) 2014 Jonathan Ong + * Copyright(c) 2014-2015 Douglas Christopher Wilson + * MIT Licensed + */ + + +'use strict'; + +/** + * Module exports. + * @public + */ + +module.exports = vhost; + +/** + * Module variables. + * @private + */ + +var ASTERISK_REGEXP = /\*/g; +var ASTERISK_REPLACE = '([^.]+)'; +var END_ANCHORED_REGEXP = /(?:^|[^\\])(?:\\\\)*\$$/; +var ESCAPE_REGEXP = /([.+?^=!:${}()|[\]/\\])/g; +var ESCAPE_REPLACE = '\\$1'; + +/** + * Create a vhost middleware. + * + * @param {string|RegExp} hostname + * @param {function} handle + * @return {Function} + * @public + */ + +function vhost(hostname, handle) { + if (!hostname) { + throw new TypeError('argument hostname is required'); + } + + if (!handle) { + throw new TypeError('argument handle is required'); + } + + if (typeof handle !== 'function') { + throw new TypeError('argument handle must be a function'); + } + + // create regular expression for hostname + var regexp = hostregexp(hostname); + + return function vhost(req, res, next) { + var vhostdata = vhostof(req, regexp); + + if (!vhostdata) { + return next(); + } + + // populate + req.vhost = vhostdata; + + // handle + handle(req, res, next); + }; +} + +/** + * Get hostname of request. + * + * @param {object} req + * @return {string} + * @private + */ + +function hostnameof(req) { + var host = + req.hostname || // express v4 + req.host || // express v3 + req.headers.host; // http + + if (!host) { + return; + } + + var offset = host[0] === '[' + ? host.indexOf(']') + 1 + : 0; + var index = host.indexOf(':', offset); + + return index !== -1 + ? host.substring(0, index) + : host; +} + +/** + * Determine if object is RegExp. + * + * @param {object} val + * @return {boolean} + * @private + */ + +function isregexp(val) { + return Object.prototype.toString.call(val) === '[object RegExp]'; +} + +/** + * Generate RegExp for given hostname value. + * + * @param {string|RegExp} val + * @private + */ + +function hostregexp(val) { + var source = !isregexp(val) + ? String(val).replace(ESCAPE_REGEXP, ESCAPE_REPLACE).replace(ASTERISK_REGEXP, ASTERISK_REPLACE) + : val.source; + + // force leading anchor matching + if (source[0] !== '^') { + source = '^' + source; + } + + // force trailing anchor matching + if (!END_ANCHORED_REGEXP.test(source)) { + source += '$'; + } + + return new RegExp(source, 'i'); +} + +/** + * Get the vhost data of the request for RegExp + * + * @param {object} req + * @param {RegExp} regexp + * @return {object} + * @private + */ + +function vhostof(req, regexp) { + var host = req.headers.host; + var hostname = hostnameof(req); + + if (!hostname) { + return; + } + + var match = regexp.exec(hostname); + + if (!match) { + return; + } + + var obj = Object.create(null); + + obj.host = host; + obj.hostname = hostname; + obj.length = match.length - 1; + + for (var i = 1; i < match.length; i++) { + obj[i - 1] = match[i]; + } + + return obj; +} diff --git a/ghost/mw-vhost/package.json b/ghost/mw-vhost/package.json index 650156e0af..36d7976dca 100644 --- a/ghost/mw-vhost/package.json +++ b/ghost/mw-vhost/package.json @@ -9,7 +9,9 @@ "dev": "echo \"Implement me!\"", "test:unit": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura mocha './test/**/*.test.js'", "test": "yarn test:unit", - "lint": "eslint . --ext .js --cache" + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" }, "files": [ "index.js", diff --git a/ghost/oembed-service/test/hello.test.js b/ghost/oembed-service/test/hello.test.js index 3f9e671446..76dd5f6ef7 100644 --- a/ghost/oembed-service/test/hello.test.js +++ b/ghost/oembed-service/test/hello.test.js @@ -2,6 +2,6 @@ const assert = require('assert'); describe('Hello world', function () { it('Runs a test', function () { - assert.equal('hello', 'hello'); + assert.ok(require('../index')); }); }); diff --git a/ghost/offers/package.json b/ghost/offers/package.json index 4d56b0e2cd..12405f8b5c 100644 --- a/ghost/offers/package.json +++ b/ghost/offers/package.json @@ -9,7 +9,9 @@ "dev": "echo \"Implement me!\"", "test:unit": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura mocha './test/**/*.test.js'", "test": "yarn test:unit", - "lint": "eslint . --ext .js --cache" + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" }, "files": [ "index.js", diff --git a/ghost/package-json/package.json b/ghost/package-json/package.json index 5dd49e08dc..ba168d9717 100644 --- a/ghost/package-json/package.json +++ b/ghost/package-json/package.json @@ -9,7 +9,9 @@ "dev": "echo \"Implement me!\"", "test:unit": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura --check-coverage mocha './test/**/*.test.js'", "test": "yarn test:unit", - "lint": "eslint . --ext .js --cache" + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" }, "files": [ "index.js", diff --git a/ghost/payments/package.json b/ghost/payments/package.json index ab890cb484..5798909f2e 100644 --- a/ghost/payments/package.json +++ b/ghost/payments/package.json @@ -9,7 +9,9 @@ "dev": "echo \"Implement me!\"", "test:unit": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura mocha './test/**/*.test.js'", "test": "yarn test:unit", - "lint": "eslint . --ext .js --cache" + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" }, "files": [ "index.js", diff --git a/ghost/security/package.json b/ghost/security/package.json index 724478e974..138b5ecd89 100644 --- a/ghost/security/package.json +++ b/ghost/security/package.json @@ -9,7 +9,9 @@ "dev": "echo \"Implement me!\"", "test:unit": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura mocha './test/**/*.test.js'", "test": "yarn test:unit", - "lint": "eslint . --ext .js --cache" + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" }, "files": [ "index.js", diff --git a/ghost/session-service/package.json b/ghost/session-service/package.json index 4296c5dcdf..db6fe3fc0a 100644 --- a/ghost/session-service/package.json +++ b/ghost/session-service/package.json @@ -9,7 +9,9 @@ "dev": "echo \"Implement me!\"", "test:unit": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura mocha './test/**/*.test.js'", "test": "yarn test:unit", - "lint": "eslint . --ext .js --cache" + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" }, "files": [ "index.js", diff --git a/ghost/settings-path-manager/package.json b/ghost/settings-path-manager/package.json index 7b0e2ae972..34aeb9a4cd 100644 --- a/ghost/settings-path-manager/package.json +++ b/ghost/settings-path-manager/package.json @@ -9,7 +9,9 @@ "dev": "echo \"Implement me!\"", "test:unit": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura --check-coverage mocha './test/**/*.test.js'", "test": "yarn test:unit", - "lint": "eslint . --ext .js --cache" + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" }, "files": [ "index.js", diff --git a/ghost/stripe/package.json b/ghost/stripe/package.json index 6769d97efc..f625db6cb2 100644 --- a/ghost/stripe/package.json +++ b/ghost/stripe/package.json @@ -9,7 +9,9 @@ "dev": "echo \"Implement me!\"", "test:unit": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura mocha './test/**/*.test.js'", "test": "yarn test:unit", - "lint": "eslint . --ext .js --cache" + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" }, "files": [ "index.js", diff --git a/ghost/update-check-service/package.json b/ghost/update-check-service/package.json index 8f132d4c1a..1b6b39e86e 100644 --- a/ghost/update-check-service/package.json +++ b/ghost/update-check-service/package.json @@ -10,7 +10,9 @@ "dev": "echo \"Implement me!\"", "test:unit": "NODE_ENV=testing c8 --all --check-coverage --reporter text --reporter cobertura mocha './test/**/*.test.js'", "test": "yarn test:unit", - "lint": "eslint . --ext .js --cache" + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" }, "files": [ "lib" diff --git a/ghost/verification-trigger/package.json b/ghost/verification-trigger/package.json index 978b467207..0fd96f50d3 100644 --- a/ghost/verification-trigger/package.json +++ b/ghost/verification-trigger/package.json @@ -9,7 +9,9 @@ "dev": "echo \"Implement me!\"", "test:unit": "NODE_ENV=testing c8 --all --check-coverage --100 --reporter text --reporter cobertura mocha './test/**/*.test.js'", "test": "yarn test:unit", - "lint": "eslint . --ext .js --cache" + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" }, "files": [ "index.js",