diff --git a/.eslintrc.js b/.eslintrc.js index c03165604..2390c486c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -5,6 +5,12 @@ const parserOptions = { sourceType: 'module', }; +const tsCommonRules = { + // This rule triggers false positives and doesn't add real type-safety value. + // See: https://typescript-eslint.io/rules/no-redundant-type-constituents/#when-not-to-use-it + '@typescript-eslint/no-redundant-type-constituents': 'off', +}; + module.exports = { root: true, extends: ['@metamask/eslint-config', '@metamask/eslint-config-nodejs'], @@ -56,6 +62,8 @@ module.exports = { extends: ['@metamask/eslint-config-typescript'], parserOptions, rules: { + ...tsCommonRules, + // Enable rules that are disabled in `@metamask/eslint-config-typescript` '@typescript-eslint/no-explicit-any': 'error', }, @@ -72,6 +80,8 @@ module.exports = { extends: ['@metamask/eslint-config-typescript'], parserOptions, rules: { + ...tsCommonRules, + // TODO: re-lint everything once the migration is done '@typescript-eslint/no-explicit-any': 'off', }, @@ -82,6 +92,8 @@ module.exports = { extends: ['@metamask/eslint-config-typescript'], parserOptions, rules: { + ...tsCommonRules, + // TODO: re-lint everything once the migration is done 'import/order': 'off', 'jsdoc/newline-after-description': 'off', @@ -93,6 +105,8 @@ module.exports = { extends: ['@metamask/eslint-config-typescript'], parserOptions, rules: { + ...tsCommonRules, + // FIXME: for some reason, it seems eslint is not able to infere those (this // works on the original repository, so there might be some side-effects now that // we are building in a monorepo) @@ -132,6 +146,8 @@ module.exports = { extends: ['@metamask/eslint-config-typescript'], parserOptions, rules: { + ...tsCommonRules, + // TODO: re-lint everything once the migration is done '@typescript-eslint/consistent-type-imports': 'off', '@typescript-eslint/naming-convention': 'off', @@ -156,6 +172,8 @@ module.exports = { extends: ['@metamask/eslint-config-typescript'], parserOptions, rules: { + ...tsCommonRules, + // TODO: re-lint everything once the migration is done '@typescript-eslint/consistent-type-definitions': 'off', '@typescript-eslint/consistent-type-imports': 'off', @@ -183,6 +201,8 @@ module.exports = { extends: ['@metamask/eslint-config-typescript'], parserOptions, rules: { + ...tsCommonRules, + // TODO: re-lint everything once the migration is done '@typescript-eslint/no-explicit-any': 'off', // FIXME: for some reason, it seems eslint is not able to infere those (this @@ -209,6 +229,8 @@ module.exports = { extends: ['@metamask/eslint-config-typescript'], parserOptions, rules: { + ...tsCommonRules, + // TODO: re-lint everything once the migration is done '@typescript-eslint/no-explicit-any': 'off', // FIXME: for some reason, it seems eslint is not able to infere those (this diff --git a/jest.config.packages.js b/jest.config.packages.js index 5153694e0..87280d8d1 100644 --- a/jest.config.packages.js +++ b/jest.config.packages.js @@ -88,8 +88,6 @@ module.exports = { moduleNameMapper: { '^@metamask/(.+)$': [ '/../$1/src', - // While still unclear why, adding the line below seems to fix the @typescript-eslint/no-redundant-type-constituents errors throughout the monorepo - '/packages/$1/src', // Some @metamask/* packages we are referencing aren't in this monorepo, // so in that case use their published versions '/../../node_modules/@metamask/$1', diff --git a/packages/keyring-eth-ledger-bridge/src/ledger-keyring-v2.test.ts b/packages/keyring-eth-ledger-bridge/src/ledger-keyring-v2.test.ts index e4bb20fed..f65636527 100644 --- a/packages/keyring-eth-ledger-bridge/src/ledger-keyring-v2.test.ts +++ b/packages/keyring-eth-ledger-bridge/src/ledger-keyring-v2.test.ts @@ -56,10 +56,11 @@ const EXPECTED_METHODS = [ * @returns The first account. */ function getFirstAccount(accounts: LedgerAccount[]): LedgerAccount { - if (accounts.length === 0) { + const [account] = accounts; + if (!account) { throw new Error('Expected at least one account'); } - return accounts[0] as LedgerAccount; + return account; } /** @@ -70,10 +71,11 @@ function getFirstAccount(accounts: LedgerAccount[]): LedgerAccount { * @returns The account at the index. */ function getAccountAt(accounts: LedgerAccount[], index: number): LedgerAccount { - if (accounts.length <= index) { + const account = accounts[index]; + if (!account) { throw new Error(`Expected account at index ${index}`); } - return accounts[index] as LedgerAccount; + return account; } /** diff --git a/packages/keyring-eth-trezor/src/trezor-keyring-v2.test.ts b/packages/keyring-eth-trezor/src/trezor-keyring-v2.test.ts index d020d26f8..2b48d623b 100644 --- a/packages/keyring-eth-trezor/src/trezor-keyring-v2.test.ts +++ b/packages/keyring-eth-trezor/src/trezor-keyring-v2.test.ts @@ -61,10 +61,11 @@ const EXPECTED_METHODS = [ * @returns The first account. */ function getFirstAccount(accounts: TrezorAccount[]): TrezorAccount { - if (accounts.length === 0) { + const [account] = accounts; + if (!account) { throw new Error('Expected at least one account'); } - return accounts[0] as TrezorAccount; + return account; } /** @@ -75,10 +76,11 @@ function getFirstAccount(accounts: TrezorAccount[]): TrezorAccount { * @returns The account at the index. */ function getAccountAt(accounts: TrezorAccount[], index: number): TrezorAccount { - if (accounts.length <= index) { + const account = accounts[index]; + if (!account) { throw new Error(`Expected account at index ${index}`); } - return accounts[index] as TrezorAccount; + return account; } /** diff --git a/packages/keyring-internal-api/src/types.ts b/packages/keyring-internal-api/src/types.ts index 3f4d3a435..619ca0b7f 100644 --- a/packages/keyring-internal-api/src/types.ts +++ b/packages/keyring-internal-api/src/types.ts @@ -1,3 +1,7 @@ +// FIXME: eslint is complaning about our account union even if those accounts +// types should all be different, so we disable this for now: +/* eslint-disable @typescript-eslint/no-duplicate-type-constituents */ + import { BtcAccountType, EthAccountType, diff --git a/tsconfig.packages.json b/tsconfig.packages.json index ec34c3fef..847976f51 100644 --- a/tsconfig.packages.json +++ b/tsconfig.packages.json @@ -28,11 +28,7 @@ * `jest.config.packages.js`. */ "paths": { - "@metamask/*": [ - "../*/src", - // While still unclear why, adding "./packages/*/src" seems to fix the @typescript-eslint/no-redundant-type-constituents errors throughout the monorepo - "./packages/*/src" - ] + "@metamask/*": ["../*/src"] } } }