Added linting for use of @tryghost/errors

refs: https://github.com/TryGhost/Toolbox/issues/147
Errors in @tryghost/errors rely on being called with an object (with a `message` member) rather than with a string.
This commit is contained in:
Sam Lord 2021-12-01 11:22:14 +00:00
parent 5e0374cfde
commit 18b8eddd0d
16 changed files with 54 additions and 37 deletions

View File

@ -40,9 +40,9 @@ module.exports = {
// Check for an activate() method on the app.
if (!_.isFunction(app.activate)) {
return Promise.reject(new errors.IncorrectUsageError(
tpl(messages.noActivateMethodLoadingAppError, {name: name})
));
return Promise.reject(new errors.IncorrectUsageError({
message: tpl(messages.noActivateMethodLoadingAppError, {name: name})
}));
}
// Wrapping the activate() with a when because it's possible

View File

@ -9,11 +9,11 @@ const MemberEmailChangeEvent = ghostBookshelf.Model.extend({
}
}, {
async edit() {
throw new errors.IncorrectUsageError('Cannot edit MemberEmailChangeEvent');
throw new errors.IncorrectUsageError({message: 'Cannot edit MemberEmailChangeEvent'});
},
async destroy() {
throw new errors.IncorrectUsageError('Cannot destroy MemberEmailChangeEvent');
throw new errors.IncorrectUsageError({message: 'Cannot destroy MemberEmailChangeEvent'});
}
});

View File

@ -9,11 +9,11 @@ const MemberLoginEvent = ghostBookshelf.Model.extend({
}
}, {
async edit() {
throw new errors.IncorrectUsageError('Cannot edit MemberLoginEvent');
throw new errors.IncorrectUsageError({message: 'Cannot edit MemberLoginEvent'});
},
async destroy() {
throw new errors.IncorrectUsageError('Cannot destroy MemberLoginEvent');
throw new errors.IncorrectUsageError({message: 'Cannot destroy MemberLoginEvent'});
}
});

View File

@ -11,7 +11,7 @@ const MemberPaidSubscriptionEvent = ghostBookshelf.Model.extend({
customQuery(qb, options) {
if (options.aggregateMRRDeltas) {
if (options.limit || options.filter) {
throw new errors.IncorrectUsageError('aggregateMRRDeltas does not work when passed a filter or limit');
throw new errors.IncorrectUsageError({message: 'aggregateMRRDeltas does not work when passed a filter or limit'});
}
const knex = ghostBookshelf.knex;
return qb.clear('select')
@ -33,11 +33,11 @@ const MemberPaidSubscriptionEvent = ghostBookshelf.Model.extend({
return options;
},
async edit() {
throw new errors.IncorrectUsageError('Cannot edit MemberPaidSubscriptionEvent');
throw new errors.IncorrectUsageError({message: 'Cannot edit MemberPaidSubscriptionEvent'});
},
async destroy() {
throw new errors.IncorrectUsageError('Cannot destroy MemberPaidSubscriptionEvent');
throw new errors.IncorrectUsageError({message: 'Cannot destroy MemberPaidSubscriptionEvent'});
}
});

View File

@ -11,7 +11,7 @@ const MemberPaymentEvent = ghostBookshelf.Model.extend({
customQuery(qb, options) {
if (options.aggregatePaymentVolume) {
if (options.limit || options.filter) {
throw new errors.IncorrectUsageError('aggregatePaymentVolume does not work when passed a filter or limit');
throw new errors.IncorrectUsageError({message: 'aggregatePaymentVolume does not work when passed a filter or limit'});
}
const knex = ghostBookshelf.knex;
return qb.clear('select')
@ -33,11 +33,11 @@ const MemberPaymentEvent = ghostBookshelf.Model.extend({
return options;
},
async edit() {
throw new errors.IncorrectUsageError('Cannot edit MemberPaymentEvent');
throw new errors.IncorrectUsageError({message: 'Cannot edit MemberPaymentEvent'});
},
async destroy() {
throw new errors.IncorrectUsageError('Cannot destroy MemberPaymentEvent');
throw new errors.IncorrectUsageError({message: 'Cannot destroy MemberPaymentEvent'});
}
});

View File

@ -19,15 +19,15 @@ const MemberProductEvent = ghostBookshelf.Model.extend({
}, {
async edit() {
throw new errors.IncorrectUsageError(
tpl(messages.cannotPerformAction, 'edit')
);
throw new errors.IncorrectUsageError({
message: tpl(messages.cannotPerformAction, 'edit')
});
},
async destroy() {
throw new errors.IncorrectUsageError(
tpl(messages.cannotPerformAction, 'destroy')
);
throw new errors.IncorrectUsageError({
message: tpl(messages.cannotPerformAction, 'destroy')
});
}
});

View File

@ -11,7 +11,9 @@ const MemberStatusEvent = ghostBookshelf.Model.extend({
customQuery(qb, options) {
if (options.aggregateStatusCounts) {
if (options.limit || options.filter) {
throw new errors.IncorrectUsageError('aggregateStatusCounts does not work when passed a filter or limit');
throw new errors.IncorrectUsageError({
message: 'aggregateStatusCounts does not work when passed a filter or limit'
});
}
const knex = ghostBookshelf.knex;
return qb.clear('select')
@ -46,11 +48,11 @@ const MemberStatusEvent = ghostBookshelf.Model.extend({
return options;
},
async edit() {
throw new errors.IncorrectUsageError('Cannot edit MemberStatusEvent');
throw new errors.IncorrectUsageError({message: 'Cannot edit MemberStatusEvent'});
},
async destroy() {
throw new errors.IncorrectUsageError('Cannot destroy MemberStatusEvent');
throw new errors.IncorrectUsageError({message: 'Cannot destroy MemberStatusEvent'});
}
});

View File

@ -11,7 +11,9 @@ const MemberSubscribeEvent = ghostBookshelf.Model.extend({
customQuery(qb, options) {
if (options.aggregateSubscriptionDeltas) {
if (options.limit || options.filter) {
throw new errors.IncorrectUsageError('aggregateSubscriptionDeltas does not work when passed a filter or limit');
throw new errors.IncorrectUsageError({
message: 'aggregateSubscriptionDeltas does not work when passed a filter or limit'
});
}
const knex = ghostBookshelf.knex;
return qb.clear('select')
@ -32,11 +34,15 @@ const MemberSubscribeEvent = ghostBookshelf.Model.extend({
return options;
},
async edit() {
throw new errors.IncorrectUsageError('Cannot edit MemberSubscribeEvent');
throw new errors.IncorrectUsageError({
message: 'Cannot edit MemberSubscribeEvent'
});
},
async destroy() {
throw new errors.IncorrectUsageError('Cannot destroy MemberSubscribeEvent');
throw new errors.IncorrectUsageError({
message: 'Cannot destroy MemberSubscribeEvent'
});
}
});

View File

@ -346,7 +346,7 @@ Settings = ghostBookshelf.Model.extend({
);
if (validationErrors.length) {
throw new errors.ValidationError(validationErrors.join('\n'));
throw new errors.ValidationError({message: validationErrors.join('\n')});
}
},
async labs(model) {

View File

@ -416,7 +416,9 @@ function partitionMembersBySegment(memberRows, segments) {
segmentedMemberRows = memberRows.filter(member => member.status !== 'free');
memberRows = memberRows.filter(member => member.status === 'free');
} else {
throw new errors.ValidationError(tpl(messages.invalidSegment));
throw new errors.ValidationError({
message: tpl(messages.invalidSegment)
});
}
partitions[memberSegment] = segmentedMemberRows;

View File

@ -98,7 +98,7 @@ class MembersConfigProvider {
*/
getStripeKeys(type) {
if (type !== 'direct' && type !== 'connect') {
throw new errors.IncorrectUsageError(tpl(messages.incorrectKeyType));
throw new errors.IncorrectUsageError({message: tpl(messages.incorrectKeyType)});
}
const secretKey = this._settingsCache.get(`stripe_${type === 'connect' ? 'connect_' : ''}secret_key`);

View File

@ -159,12 +159,16 @@ const membersService = {
}
if (stripeService.api.configured && stripeService.api.mode === 'live') {
throw new errors.IncorrectUsageError(tpl(messages.noLiveKeysInDevelopment));
throw new errors.IncorrectUsageError({
message: tpl(messages.noLiveKeysInDevelopment)
});
}
} else {
const siteUrl = urlUtils.getSiteUrl();
if (!/^https/.test(siteUrl) && stripeService.api.configured) {
throw new errors.IncorrectUsageError(tpl(messages.sslRequiredForStripe));
throw new errors.IncorrectUsageError({
message: tpl(messages.sslRequiredForStripe)
});
}
}
if (!membersApi) {

View File

@ -63,7 +63,7 @@ async function getStripeConnectTokenData(encodedData, getSessionProp) {
const state = await getSessionProp(STATE_PROP);
if (state !== data.s) {
throw new errors.NoPermissionError(tpl(messages.incorrectState));
throw new errors.NoPermissionError({message: tpl(messages.incorrectState)});
}
return {
@ -81,7 +81,9 @@ function checkCanConnect() {
const siteUrlUsingSSL = /^https/.test(siteUrl);
const cannotConnectToStripe = productionMode && !siteUrlUsingSSL;
if (cannotConnectToStripe) {
throw new errors.BadRequestError('Cannot connect to stripe unless site is using https://');
throw new errors.BadRequestError({
message: 'Cannot connect to stripe unless site is using https://'
});
}
}

View File

@ -107,6 +107,7 @@ module.exports.enabledHelper = function enabledHelper(options, callback) {
});
errDetails.help = tpl(options.errorHelp || messages.errorHelp, {url: options.helpUrl});
// eslint-disable-next-line no-restricted-syntax
logging.error(new errors.DisabledFeatureError(errDetails));
const {SafeString} = require('express-hbs');

View File

@ -183,7 +183,7 @@
"coffeescript": "2.6.1",
"cssnano": "5.0.12",
"eslint": "7.32.0",
"eslint-plugin-ghost": "2.9.0",
"eslint-plugin-ghost": "2.10.0",
"grunt": "1.4.1",
"grunt-bg-shell": "2.3.3",
"grunt-contrib-clean": "2.0.0",

View File

@ -4315,10 +4315,10 @@ eslint-plugin-filenames@1.3.2:
lodash.snakecase "4.1.1"
lodash.upperfirst "4.3.1"
eslint-plugin-ghost@2.9.0:
version "2.9.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-ghost/-/eslint-plugin-ghost-2.9.0.tgz#96992d2a240f0c41011c63107ed7686a33495401"
integrity sha512-pc/nFdYjnPmAF9Cs4BhscrE0MhWBUxQlX3gZ5XqkJOP3MqNsuYeecz85QTG6IvjarKLhr6EklVNGoQ42BaJnjA==
eslint-plugin-ghost@2.10.0:
version "2.10.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-ghost/-/eslint-plugin-ghost-2.10.0.tgz#84ef189363d6c1214130145fb24894a6540adb5d"
integrity sha512-IB/DSVbyWYY3X6IatuPqSwCcQPVxxOaPOfKVQcig6ybzWPqyxh1F3qr8f1adJaY67dSmc0u+Hj6aQU75kBlVXw==
dependencies:
"@kapouer/eslint-plugin-no-return-in-loop" "1.0.0"
eslint-plugin-ember "10.5.7"