From 0cad69de883c1dbbfd57a354e8f13ea992832aff Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 9 Jul 2021 08:27:27 +0000 Subject: [PATCH 1/2] chore(deps-dev): bump eslint-config-opencollective from 2.2.0 to 3.0.0 Bumps [eslint-config-opencollective](https://github.com/opencollective/eslint-config-opencollective) from 2.2.0 to 3.0.0. - [Release notes](https://github.com/opencollective/eslint-config-opencollective/releases) - [Commits](https://github.com/opencollective/eslint-config-opencollective/commits/3.0.0) Signed-off-by: dependabot[bot] --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 60ec69427e5..38f4b7d268f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9142,9 +9142,9 @@ } }, "eslint-config-opencollective": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/eslint-config-opencollective/-/eslint-config-opencollective-2.2.0.tgz", - "integrity": "sha512-QVNCe+RTTvU9/h6PfbqAW7hI4RvtxIcQXJ27gYy23ksCX0ngERRfHEeYntuoFNHfJFRvqtqB4ShARssekupY5g==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/eslint-config-opencollective/-/eslint-config-opencollective-3.0.0.tgz", + "integrity": "sha512-OihvdzkvJN5wDwOcSabnf5qq5dc+2z/kqPeAjl1jpa1JR2CSVZ/wGN+xwG92/WOtNta3a3FRa6CBj7LFH/B3Fg==", "dev": true }, "eslint-import-resolver-node": { diff --git a/package.json b/package.json index fe505010f51..b9213cba37b 100644 --- a/package.json +++ b/package.json @@ -140,7 +140,7 @@ "commitizen": "^4.2.4", "cz-conventional-changelog": "^3.3.0", "eslint": "^7.31.0", - "eslint-config-opencollective": "^2.2.0", + "eslint-config-opencollective": "^3.0.0", "eslint-plugin-babel": "^5.3.1", "eslint-plugin-graphql": "^4.0.0", "eslint-plugin-import": "^2.23.4", From 2502b358a54e2e288daa4e12fcb2900611807a3a Mon Sep 17 00:00:00 2001 From: Benjamin Piouffle Date: Fri, 9 Jul 2021 11:03:14 +0200 Subject: [PATCH 2/2] chore: Enforce eqeqeq ESLint rule --- cron/monthly/host-settlement.ts | 2 +- scripts/check-collective-spam-bayes.js | 4 ++-- scripts/collective-image-check.js | 4 ++-- scripts/fixes/refund-stripe-transaction.ts | 2 +- scripts/legacy-host-settlement.js | 2 +- scripts/paypal/payment-reconciliator.ts | 2 +- scripts/privacy-add-credit-card.js | 2 +- scripts/privacy-resync-card.js | 2 +- scripts/update-hosts-2020-12-15.js | 2 +- scripts/update-hosts-2021-04-30.js | 4 ++-- server/graphql/v2/input/AccountReferenceInput.js | 4 ++-- server/graphql/v2/object/Expense.js | 2 +- server/lib/currency.ts | 2 +- server/lib/handlebars.js | 4 +++- server/lib/host-metrics.js | 2 +- server/lib/prepaid-budget.js | 2 +- server/lib/privacy.ts | 2 +- server/lib/utils.js | 2 +- server/middleware/authentication.js | 2 +- server/models/Collective.js | 2 +- server/paymentProviders/opencollective/giftcard.js | 4 ++-- server/paymentProviders/opencollective/prepaid.js | 2 +- server/paymentProviders/privacy/index.ts | 4 ++-- test/cron/monthly/host-settlement.test.js | 6 +++--- test/server/graphql/v1/createOrder.test.js | 2 +- test/server/graphql/v2/mutation/GuestMutations.test.ts | 2 +- test/server/paymentProviders/stripe/alipay.test.ts | 2 +- 27 files changed, 37 insertions(+), 35 deletions(-) diff --git a/cron/monthly/host-settlement.ts b/cron/monthly/host-settlement.ts index 1699a23913d..799f66fd09f 100644 --- a/cron/monthly/host-settlement.ts +++ b/cron/monthly/host-settlement.ts @@ -78,7 +78,7 @@ export async function run(baseDate: Date | moment.Moment = defaultDate): Promise const pendingPlatformTips = await getPendingPlatformTips(host, { startDate, endDate }); const pendingHostFeeShare = await getPendingHostFeeShare(host, { startDate, endDate }); - if (HOST_ID && host.id != HOST_ID) { + if (HOST_ID && host.id !== parseInt(HOST_ID)) { continue; } diff --git a/scripts/check-collective-spam-bayes.js b/scripts/check-collective-spam-bayes.js index 6e54ce41ad1..2b55e3c2373 100644 --- a/scripts/check-collective-spam-bayes.js +++ b/scripts/check-collective-spam-bayes.js @@ -95,7 +95,7 @@ async function run() { } } } - if (collective.type == 'USER') { + if (collective.type === 'USER') { // Skip Accounts that are administrating account with transactions const accounts = await collective.getMemberships({ role: 'ADMIN' }); for (const account of accounts) { @@ -107,7 +107,7 @@ async function run() { } if (!skip) { report(collective, 'NEW'); - if (collective.type == 'USER') { + if (collective.type === 'USER') { const accounts = await collective.getMemberships({ role: 'ADMIN' }); for (const account of accounts) { report(account, 'ADMIN FROM'); diff --git a/scripts/collective-image-check.js b/scripts/collective-image-check.js index f36e02326ef..91701b09fef 100644 --- a/scripts/collective-image-check.js +++ b/scripts/collective-image-check.js @@ -25,7 +25,7 @@ async function main() { console.log(e); continue; } - if (response.status == 404) { + if (response.status === 404) { console.log(`Image for ${collective.slug} not found: ${collective.image}`); try { await collective.update({ image: null }); @@ -34,7 +34,7 @@ async function main() { } continue; } - if (response.status == 403) { + if (response.status === 403) { console.log(`Image for ${collective.slug} access denied: ${collective.image}`); try { await collective.update({ image: null }); diff --git a/scripts/fixes/refund-stripe-transaction.ts b/scripts/fixes/refund-stripe-transaction.ts index ebdfae60d35..3031aef130f 100644 --- a/scripts/fixes/refund-stripe-transaction.ts +++ b/scripts/fixes/refund-stripe-transaction.ts @@ -36,7 +36,7 @@ const refund = async transactionId => { { stripeAccount: hostStripeAccount.username }, ); - if (refund.status == 'succeeded') { + if (refund.status === 'succeeded') { await transaction.update({ data: { ...transaction.data, refund } }); console.log('Refunded succeeded!'); } else { diff --git a/scripts/legacy-host-settlement.js b/scripts/legacy-host-settlement.js index c6004109df1..963581e5dea 100644 --- a/scripts/legacy-host-settlement.js +++ b/scripts/legacy-host-settlement.js @@ -287,7 +287,7 @@ export async function run() { const byHost = groupBy(pastMonthTransactions, 'HostCollectiveId'); for (const [hostId, hostTransactions] of entries(byHost)) { - if (HOST_ID && hostId != HOST_ID) { + if (HOST_ID && hostId !== parseInt(HOST_ID)) { continue; } diff --git a/scripts/paypal/payment-reconciliator.ts b/scripts/paypal/payment-reconciliator.ts index cd0b85fc13d..2f4942f7b4b 100755 --- a/scripts/paypal/payment-reconciliator.ts +++ b/scripts/paypal/payment-reconciliator.ts @@ -59,7 +59,7 @@ async function* getPaypalPaymentOrdersIterator(host, orderWhere) { yield orders.shift(); } - if (!nbOrders || nbOrders % limit != 0) { + if (!nbOrders || nbOrders % limit !== 0) { break; } else { offset += nbOrders; diff --git a/scripts/privacy-add-credit-card.js b/scripts/privacy-add-credit-card.js index 8ea9340c495..d82da629058 100755 --- a/scripts/privacy-add-credit-card.js +++ b/scripts/privacy-add-credit-card.js @@ -19,7 +19,7 @@ const run = async (CollectiveId, cardNumber, expireDate, cvv) => { }; if (!module.parent) { - if (process.argv.length < 4 || process.argv[2] == 'help') { + if (process.argv.length < 4 || process.argv[2] === 'help') { console.log( '\nUsage:\n npm run script ./scripts/encrypt.js collectiveId "xxxx xxxx xxxx xxxx" "mm/yyyy" "cvv"\n', ); diff --git a/scripts/privacy-resync-card.js b/scripts/privacy-resync-card.js index 07071027a1b..8cf85f11489 100755 --- a/scripts/privacy-resync-card.js +++ b/scripts/privacy-resync-card.js @@ -47,7 +47,7 @@ const run = async cardId => { }; if (!module.parent) { - if (process.argv.length < 3 || process.argv[2] == 'help') { + if (process.argv.length < 3 || process.argv[2] === 'help') { console.log('\nUsage:\n npm run script ./scripts/privacy-resync-card.js cardId\n'); process.exit(0); } diff --git a/scripts/update-hosts-2020-12-15.js b/scripts/update-hosts-2020-12-15.js index 71365a68689..f53a6dc1a23 100644 --- a/scripts/update-hosts-2020-12-15.js +++ b/scripts/update-hosts-2020-12-15.js @@ -30,7 +30,7 @@ async function run({ dryRun } = {}) { } } - if (host.platformFeePercent != 0) { + if (host.platformFeePercent !== 0) { console.log(`- Activating Platform Tips`); if (!dryRun) { await host.update({ platformFeePercent: 0 }); diff --git a/scripts/update-hosts-2021-04-30.js b/scripts/update-hosts-2021-04-30.js index 5f32be6b596..33d91cab5b0 100644 --- a/scripts/update-hosts-2021-04-30.js +++ b/scripts/update-hosts-2021-04-30.js @@ -29,7 +29,7 @@ async function run({ dryRun } = {}) { } } - if (host.hostFeePercent != 0) { + if (host.hostFeePercent !== 0) { console.log(`- Updating Plan to grow-plan-2021`); if (!dryRun) { await host.update({ plan: 'grow-plan-2021' }); @@ -41,7 +41,7 @@ async function run({ dryRun } = {}) { } } - if (host.platformFeePercent != 0) { + if (host.platformFeePercent !== 0) { console.log(`- Activating Platform Tips (updating platformFeePercent to 0)`); if (!dryRun) { // This will NOT cascade to all Collectives diff --git a/server/graphql/v2/input/AccountReferenceInput.js b/server/graphql/v2/input/AccountReferenceInput.js index 627a2e7fcfa..4e770d39bfd 100644 --- a/server/graphql/v2/input/AccountReferenceInput.js +++ b/server/graphql/v2/input/AccountReferenceInput.js @@ -75,10 +75,10 @@ export const fetchAccountWithReference = async ( }; let collective; - if (input.id && typeof input.id == 'string') { + if (input.id && typeof input.id === 'string') { const id = idDecode(input.id, 'account'); collective = await loadCollectiveById(id); - } else if (input.legacyId || typeof input.id == 'number') { + } else if (input.legacyId || typeof input.id === 'number') { collective = await loadCollectiveById(input.legacyId || input.id); } else if (input.slug) { collective = await models.Collective.findOne( diff --git a/server/graphql/v2/object/Expense.js b/server/graphql/v2/object/Expense.js index 9851adb6ed0..25331f4341c 100644 --- a/server/graphql/v2/object/Expense.js +++ b/server/graphql/v2/object/Expense.js @@ -247,7 +247,7 @@ const Expense = new GraphQLObjectType({ type: GraphQLJSON, description: 'Drafted field values that were still not persisted', async resolve(expense) { - if (expense.status == expenseStatus.DRAFT) { + if (expense.status === expenseStatus.DRAFT) { return pick(expense.data, EXPENSE_DRAFT_PUBLIC_FIELDS); } }, diff --git a/server/lib/currency.ts b/server/lib/currency.ts index f61a202b2d7..abde94f64bf 100644 --- a/server/lib/currency.ts +++ b/server/lib/currency.ts @@ -13,7 +13,7 @@ import logger from './logger'; const debug = debugLib('currency'); function getDate(date: string | Date = 'latest') { - if (typeof date == 'string') { + if (typeof date === 'string') { return date; } else if (date.getFullYear) { date.setTime(date.getTime() + date.getTimezoneOffset() * 60 * 1000); diff --git a/server/lib/handlebars.js b/server/lib/handlebars.js index 83c52532559..a75aaeb4d11 100644 --- a/server/lib/handlebars.js +++ b/server/lib/handlebars.js @@ -15,10 +15,12 @@ import { handlebars.registerHelper('ifCond', function (v1, operator, v2, options) { switch (operator) { case '==': + // eslint-disable-next-line eqeqeq return v1 == v2 ? options.fn(this) : options.inverse(this); case '===': return v1 === v2 ? options.fn(this) : options.inverse(this); case '!=': + // eslint-disable-next-line eqeqeq return v1 != v2 ? options.fn(this) : options.inverse(this); case '!==': return v1 !== v2 ? options.fn(this) : options.inverse(this); @@ -128,7 +130,7 @@ handlebars.registerHelper('currency', (value, props) => { res = `+${res}`; } // If we are limited in space, no need to show the trailing .00 - if (size && precision == 2) { + if (size && precision === 2) { res = res.replace(/\.00$/, ''); } if (size) { diff --git a/server/lib/host-metrics.js b/server/lib/host-metrics.js index 391b9de662f..afee943723c 100644 --- a/server/lib/host-metrics.js +++ b/server/lib/host-metrics.js @@ -7,7 +7,7 @@ import { getFxRate } from './currency'; import { parseToBoolean } from './utils'; function oppositeTotal(total) { - return total != 0 ? -total : total; + return total !== 0 ? -total : total; } async function computeTotal(results, currency) { diff --git a/server/lib/prepaid-budget.js b/server/lib/prepaid-budget.js index 076bbb28b9d..d55bd1214b4 100644 --- a/server/lib/prepaid-budget.js +++ b/server/lib/prepaid-budget.js @@ -5,7 +5,7 @@ import { TransactionKind } from '../constants/transaction-kind'; import models from '../models'; export function isPrepaidBudgetOrder(order) { - return order.tier && order.tier.slug == 'prepaid-budget' && order.collective.slug === 'opensource'; + return order.tier && order.tier.slug === 'prepaid-budget' && order.collective.slug === 'opensource'; } export async function createPrepaidPaymentMethod(originalCreditTransaction) { diff --git a/server/lib/privacy.ts b/server/lib/privacy.ts index 3dd1c3501c5..c4ca4b5a78d 100644 --- a/server/lib/privacy.ts +++ b/server/lib/privacy.ts @@ -64,7 +64,7 @@ export const findCard = async (token: string, cardProperties: Partial): Pr while (keepGoing) { const cards = await listCards(token, undefined, { page, page_size: 500 }); debug(`got page ${page} with ${cards.length} cards...`); - if (cards.length == 0) { + if (cards.length === 0) { return undefined; } const card = find(cards, cardProperties); diff --git a/server/lib/utils.js b/server/lib/utils.js index 4f2e40adf2b..e3d41e921d0 100644 --- a/server/lib/utils.js +++ b/server/lib/utils.js @@ -52,7 +52,7 @@ export function getDomain(url = '') { if (arrLen > 2) { domain = `${splitArr[arrLen - 2]}.${splitArr[arrLen - 1]}`; // check to see if it's using a Country Code Top Level Domain (ccTLD) (i.e. ".me.uk") - if (splitArr[arrLen - 1].length == 2 && splitArr[arrLen - 1].length == 2) { + if (splitArr[arrLen - 1].length === 2 && splitArr[arrLen - 1].length === 2) { // this is using a ccTLD domain = `${splitArr[arrLen - 3]}.${domain}`; } diff --git a/server/middleware/authentication.js b/server/middleware/authentication.js index 5c214264f60..fc1eee96b92 100644 --- a/server/middleware/authentication.js +++ b/server/middleware/authentication.js @@ -188,7 +188,7 @@ export const authenticateService = (req, res, next) => { const opts = { callbackURL: getOAuthCallbackUrl(req) }; if (service === 'github') { - if (context == 'createCollective') { + if (context === 'createCollective') { opts.scope = [ // We need this to call github.getOrgMemberships and check if the user is an admin of a given Organization 'read:org', diff --git a/server/models/Collective.js b/server/models/Collective.js index b9a25115990..eecae591397 100644 --- a/server/models/Collective.js +++ b/server/models/Collective.js @@ -2054,7 +2054,7 @@ function defineModel() { */ Collective.prototype.changeHost = async function (newHostCollectiveId, remoteUser, options) { // Skip - if (this.HostCollectiveId == newHostCollectiveId) { + if (this.HostCollectiveId === newHostCollectiveId) { return this; } diff --git a/server/paymentProviders/opencollective/giftcard.js b/server/paymentProviders/opencollective/giftcard.js index 67063c0c608..7a98f368df5 100644 --- a/server/paymentProviders/opencollective/giftcard.js +++ b/server/paymentProviders/opencollective/giftcard.js @@ -56,7 +56,7 @@ async function getBalance(paymentMethod) { }); let spent = 0; for (const transaction of allTransactions) { - if (transaction.currency != paymentMethod.currency) { + if (transaction.currency !== paymentMethod.currency) { const fxRate = await currency.getFxRate(transaction.currency, paymentMethod.currency); spent += transaction.netAmountInCollectiveCurrency * fxRate; } else { @@ -89,7 +89,7 @@ async function processOrder(order) { } // converting(or keeping if it's the same currency) order amount to the payment method currency let orderAmountInPaymentMethodCurrency = order.totalAmount; - if (order.currency != paymentMethod.currency) { + if (order.currency !== paymentMethod.currency) { const fxRate = await currency.getFxRate(order.currency, paymentMethod.currency); orderAmountInPaymentMethodCurrency = order.totalAmount * fxRate; } diff --git a/server/paymentProviders/opencollective/prepaid.js b/server/paymentProviders/opencollective/prepaid.js index c3c513107f1..85bbbd3fef9 100644 --- a/server/paymentProviders/opencollective/prepaid.js +++ b/server/paymentProviders/opencollective/prepaid.js @@ -47,7 +47,7 @@ async function getBalance(paymentMethod) { }); let spent = 0; for (const transaction of allTransactions) { - if (transaction.currency != paymentMethod.currency) { + if (transaction.currency !== paymentMethod.currency) { const fxRate = await getFxRate(transaction.currency, paymentMethod.currency); spent += transaction.netAmountInCollectiveCurrency * fxRate; } else { diff --git a/server/paymentProviders/privacy/index.ts b/server/paymentProviders/privacy/index.ts index 7a8c9f871b6..3f6b59e61a0 100644 --- a/server/paymentProviders/privacy/index.ts +++ b/server/paymentProviders/privacy/index.ts @@ -278,9 +278,9 @@ const autoPauseResumeCard = async (virtualCard: VirtualCardModel) => { const pendingExpenses = await virtualCard.getExpensesMissingDetails(); const hasPendingExpenses = !isEmpty(pendingExpenses); - if (hasPendingExpenses && virtualCard.data.state == 'OPEN') { + if (hasPendingExpenses && virtualCard.data.state === 'OPEN') { await pauseCard(virtualCard); - } else if (!hasPendingExpenses && virtualCard.data.state == 'PAUSED') { + } else if (!hasPendingExpenses && virtualCard.data.state === 'PAUSED') { await resumeCard(virtualCard); } }; diff --git a/test/cron/monthly/host-settlement.test.js b/test/cron/monthly/host-settlement.test.js index 76d9e448251..68193dfd014 100644 --- a/test/cron/monthly/host-settlement.test.js +++ b/test/cron/monthly/host-settlement.test.js @@ -167,12 +167,12 @@ describe('cron/monthly/host-settlement', () => { }); it('should invoice platform tips not collected through Stripe', async () => { - const platformTipsItem = expense.items.find(p => p.description == 'Platform Tips'); + const platformTipsItem = expense.items.find(p => p.description === 'Platform Tips'); expect(platformTipsItem).to.have.property('amount', Math.round(1000 / 1.23)); }); it('should invoice pending shared host revenue', async () => { - const sharedRevenueItem = expense.items.find(p => p.description == 'Shared Revenue'); + const sharedRevenueItem = expense.items.find(p => p.description === 'Shared Revenue'); expect(sharedRevenueItem).to.have.property('amount', Math.round(1600 * 0.15)); }); @@ -182,7 +182,7 @@ describe('cron/monthly/host-settlement', () => { }); it('should consider fixed fee per host collective', async () => { - const reimburseItem = expense.items.find(p => p.description == 'Fixed Fee per Hosted Collective'); + const reimburseItem = expense.items.find(p => p.description === 'Fixed Fee per Hosted Collective'); expect(reimburseItem).to.have.property('amount', 100); }); diff --git a/test/server/graphql/v1/createOrder.test.js b/test/server/graphql/v1/createOrder.test.js index db2f8f7e971..f823918ff12 100644 --- a/test/server/graphql/v1/createOrder.test.js +++ b/test/server/graphql/v1/createOrder.test.js @@ -289,7 +289,7 @@ describe('server/graphql/v1/createOrder', () => { where: { OrderId: res.data.createOrder.id }, }); expect(transactionsCount).to.equal(0); - await utils.waitForCondition(() => emailSendMessageSpy.callCount == 2); + await utils.waitForCondition(() => emailSendMessageSpy.callCount === 2); expect(emailSendMessageSpy.callCount).to.equal(2); const pendingEmailArgs = emailSendMessageSpy.args.find(callArgs => diff --git a/test/server/graphql/v2/mutation/GuestMutations.test.ts b/test/server/graphql/v2/mutation/GuestMutations.test.ts index 3049057574c..c60056d5fd7 100644 --- a/test/server/graphql/v2/mutation/GuestMutations.test.ts +++ b/test/server/graphql/v2/mutation/GuestMutations.test.ts @@ -83,7 +83,7 @@ describe('server/graphql/v2/mutation/GuestMutations', () => { expect(result.data.sendGuestConfirmationEmail).to.be.true; console.log(result); - await waitForCondition(() => emailSendMessageSpy.callCount == 1); + await waitForCondition(() => emailSendMessageSpy.callCount === 1); expect(emailSendMessageSpy.callCount).to.equal(1); const [recipient, subject, body] = emailSendMessageSpy.args[0]; diff --git a/test/server/paymentProviders/stripe/alipay.test.ts b/test/server/paymentProviders/stripe/alipay.test.ts index 0b1b4755610..7ed09933e7a 100644 --- a/test/server/paymentProviders/stripe/alipay.test.ts +++ b/test/server/paymentProviders/stripe/alipay.test.ts @@ -101,7 +101,7 @@ describe('server/paymentProviders/stripe/alipay', () => { expect(transactions).to.be.an('array').of.length(4); - const credit = transactions.find(t => t.type == 'CREDIT' && t.kind === 'CONTRIBUTION'); + const credit = transactions.find(t => t.type === 'CREDIT' && t.kind === 'CONTRIBUTION'); expect(credit).to.have.property('amount', 10000); expect(credit).to.have.property('currency', 'USD'); expect(credit).to.have.property('OrderId', order.id);