Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -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',
},
Expand All @@ -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',
},
Expand All @@ -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',
Expand All @@ -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)
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions jest.config.packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ module.exports = {
moduleNameMapper: {
'^@metamask/(.+)$': [
'<rootDir>/../$1/src',
// While still unclear why, adding the line below seems to fix the @typescript-eslint/no-redundant-type-constituents errors throughout the monorepo
'<rootDir>/packages/$1/src',
// Some @metamask/* packages we are referencing aren't in this monorepo,
// so in that case use their published versions
'<rootDir>/../../node_modules/@metamask/$1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand Down
10 changes: 6 additions & 4 deletions packages/keyring-eth-trezor/src/trezor-keyring-v2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions packages/keyring-internal-api/src/types.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
6 changes: 1 addition & 5 deletions tsconfig.packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
}
}
Loading