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
This commit is contained in:
Hannah Wolfe 2023-06-12 15:27:12 +01:00
parent b697ca2768
commit b80b90229f
35 changed files with 282 additions and 220 deletions

View File

@ -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",

View File

@ -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",

View File

@ -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');

View File

@ -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'
};

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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');

171
ghost/mw-vhost/lib/vhost.js Normal file
View File

@ -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;
}

View File

@ -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",

View File

@ -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'));
});
});

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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"

View File

@ -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",