From 548b0bbbd5b3bab78647be3db319bd21530a6792 Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Wed, 12 Aug 2020 20:32:44 -0230 Subject: [PATCH] Fix no-eq-null issues (#9205) See [`no-eq-null`](https://eslint.org/docs/rules/no-eq-null) for more information. This change enables `no-eq-null` and fixes the issues raised by the rule. --- .eslintrc.js | 1 + ui/app/components/app/asset-list-item/asset-list-item.js | 2 +- ui/app/helpers/utils/conversion-util.js | 2 +- ui/app/helpers/utils/i18n-helper.js | 5 ++++- ui/app/hooks/useTransactionDisplayData.js | 2 +- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index c467ab1eeb9f..9ac053afcf61 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -49,6 +49,7 @@ module.exports = { 'guard-for-in': 'error', 'no-case-declarations': 'error', 'no-empty': 'error', + 'no-eq-null': 'error', 'no-loop-func': 'error', 'no-useless-catch': 'error', 'no-useless-concat': 'error', diff --git a/ui/app/components/app/asset-list-item/asset-list-item.js b/ui/app/components/app/asset-list-item/asset-list-item.js index bacae2d3a594..1b7cbe672322 100644 --- a/ui/app/components/app/asset-list-item/asset-list-item.js +++ b/ui/app/components/app/asset-list-item/asset-list-item.js @@ -60,7 +60,7 @@ const AssetListItem = ({ : null const sendTokenButton = useMemo(() => { - if (tokenAddress == null) { + if (tokenAddress === null || tokenAddress === undefined) { return null } return ( diff --git a/ui/app/helpers/utils/conversion-util.js b/ui/app/helpers/utils/conversion-util.js index adc9b65e28b3..784fd4e12d58 100644 --- a/ui/app/helpers/utils/conversion-util.js +++ b/ui/app/helpers/utils/conversion-util.js @@ -99,7 +99,7 @@ const converter = ({ } if (fromCurrency !== toCurrency) { - if (conversionRate == null) { + if (conversionRate === null || conversionRate === undefined) { throw new Error(`Converting from ${fromCurrency} to ${toCurrency} requires a conversionRate, but one was not provided`) } let rate = toBigNumber.dec(conversionRate) diff --git a/ui/app/helpers/utils/i18n-helper.js b/ui/app/helpers/utils/i18n-helper.js index 7fccc92cbf83..ff3514f847e3 100644 --- a/ui/app/helpers/utils/i18n-helper.js +++ b/ui/app/helpers/utils/i18n-helper.js @@ -56,7 +56,10 @@ export const getMessage = (localeCode, localeMessages, key, substitutions) => { return part } const substituteIndex = Number(subMatch[1]) - 1 - if (substitutions[substituteIndex] == null && !missingSubstitutionErrors[localeCode]?.[key]) { + if ( + (substitutions[substituteIndex] === null || substitutions[substituteIndex] === undefined) && + !missingSubstitutionErrors[localeCode]?.[key] + ) { if (!missingSubstitutionErrors[localeCode]) { missingSubstitutionErrors[localeCode] = {} } diff --git a/ui/app/hooks/useTransactionDisplayData.js b/ui/app/hooks/useTransactionDisplayData.js index 52d161e7dd78..c146d142d2f0 100644 --- a/ui/app/hooks/useTransactionDisplayData.js +++ b/ui/app/hooks/useTransactionDisplayData.js @@ -99,7 +99,7 @@ export function useTransactionDisplayData (transactionGroup) { // 3. Deposit // 4. Site interaction // 5. Approval - if (transactionCategory == null) { + if (transactionCategory === null || transactionCategory === undefined) { category = TRANSACTION_CATEGORY_SIGNATURE_REQUEST title = t('signatureRequest') subtitle = origin