Skip to content

Commit

Permalink
Re-enable @typescript-eslint/consistent-type-definitions (#1933)
Browse files Browse the repository at this point in the history
This ESLint rule was disabled in a previous commit when our ESLint
config packages were bumped, because it caused lint violations.

This commit re-enables this rule going forward. However, since fixing
the lint violations by converting `interface` to `type`s would cause
breaking changes, this commit adds inline overrides to allow existing
`interface`s to exist.
  • Loading branch information
mcmire authored Nov 7, 2023
1 parent b48538a commit c864e48
Show file tree
Hide file tree
Showing 28 changed files with 246 additions and 11 deletions.
4 changes: 0 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ module.exports = {
project: ['./tsconfig.packages.json'],
},
rules: {
// disabled due to incompatibility with Record<string, unknown>
// See https://github.com/Microsoft/TypeScript/issues/15300#issuecomment-702872440
'@typescript-eslint/consistent-type-definitions': 'off',

// TODO: auto-fix breaks stuff
'@typescript-eslint/promise-function-async': 'off',

Expand Down
9 changes: 9 additions & 0 deletions packages/address-book-controller/src/AddressBookController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import type { Hex } from '@metamask/utils';
* @property name - Nickname associated with this address
* @property importTime - Data time when an account as created/imported
*/
// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface ContactEntry {
address: string;
name: string;
Expand All @@ -39,6 +42,9 @@ export enum AddressType {
* @property isEns - is the entry an ENS name
* @property addressType - is the type of this address
*/
// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface AddressBookEntry {
address: string;
name: string;
Expand All @@ -54,6 +60,9 @@ export interface AddressBookEntry {
* Address book controller state
* @property addressBook - Array of contact entry objects
*/
// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface AddressBookState extends BaseState {
addressBook: { [chainId: Hex]: { [address: string]: AddressBookEntry } };
}
Expand Down
9 changes: 9 additions & 0 deletions packages/assets-controllers/src/AccountTrackerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import { Mutex } from 'async-mutex';
* Account information object
* @property balance - Hex string of an account balancec in wei
*/
// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface AccountInformation {
balance: string;
}
Expand All @@ -27,6 +30,9 @@ export interface AccountInformation {
* Account tracker controller configuration
* @property provider - Provider used to create a new underlying EthQuery instance
*/
// This interface was created before this ESLint rule was added.
// Remove in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface AccountTrackerConfig extends BaseConfig {
interval: number;
provider?: Provider;
Expand All @@ -38,6 +44,9 @@ export interface AccountTrackerConfig extends BaseConfig {
* Account tracker controller state
* @property accounts - Map of addresses to account information
*/
// This interface was created before this ESLint rule was added.
// Remove in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface AccountTrackerState extends BaseState {
accounts: { [address: string]: AccountInformation };
}
Expand Down
6 changes: 6 additions & 0 deletions packages/assets-controllers/src/AssetsContractController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export const MISSING_PROVIDER_ERROR =
* Assets Contract controller configuration
* @property provider - Provider used to create a new web3 instance
*/
// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface AssetsContractConfig extends BaseConfig {
provider: any;
ipfsGateway: string;
Expand All @@ -62,6 +65,9 @@ export interface AssetsContractConfig extends BaseConfig {
* Key value object containing the balance for each tokenAddress
* @property [tokenAddress] - Address of the token
*/
// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface BalanceMap {
[tokenAddress: string]: BN;
}
Expand Down
18 changes: 18 additions & 0 deletions packages/assets-controllers/src/NftController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ type SuggestedNftMeta = {
* @property isCurrentlyOwned - Boolean indicating whether the address/chainId combination where it's currently stored currently owns this NFT
* @property transactionId - Transaction Id associated with the NFT
*/
// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface Nft extends NftMetadata {
tokenId: string;
address: string;
Expand All @@ -94,6 +97,9 @@ export interface Nft extends NftMetadata {
* @property schemaName - The schema followed by the contract, it could be `ERC721` or `ERC1155`
* @property externalLink - External link containing additional information
*/
// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface NftContract {
name?: string;
logo?: string;
Expand Down Expand Up @@ -125,6 +131,9 @@ export interface NftContract {
* @property creator - The NFT owner information object
* @property standard - NFT standard name for the NFT, e.g., ERC-721 or ERC-1155
*/
// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface NftMetadata {
name: string | null;
description: string | null;
Expand All @@ -151,6 +160,9 @@ export interface NftMetadata {
* NFT controller configuration
* @property selectedAddress - Vault selected address
*/
// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface NftConfig extends BaseConfig {
selectedAddress: string;
chainId: Hex;
Expand All @@ -168,6 +180,9 @@ export interface NftConfig extends BaseConfig {
* @property allNfts - Object containing NFTs per account and network
* @property ignoredNfts - List of NFTs that should be ignored
*/
// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface NftState extends BaseState {
allNftContracts: {
[key: string]: { [chainId: Hex]: NftContract[] };
Expand All @@ -179,6 +194,9 @@ export interface NftState extends BaseState {
const ALL_NFTS_STATE_KEY = 'allNfts';
const ALL_NFTS_CONTRACTS_STATE_KEY = 'allNftContracts';

// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface NftAsset {
address: string;
tokenId: string;
Expand Down
15 changes: 15 additions & 0 deletions packages/assets-controllers/src/NftDetectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ const DEFAULT_INTERVAL = 180000;
* @property creator - The NFT owner information object
* @property lastSale - When this item was last sold
*/
// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface ApiNft {
token_id: string;
num_sales: number | null;
Expand Down Expand Up @@ -72,6 +75,9 @@ export interface ApiNft {
* @property description - The NFT contract description
* @property external_link - External link containing additional information
*/
// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface ApiNftContract {
address: string;
asset_contract_type: string | null;
Expand All @@ -95,6 +101,9 @@ export interface ApiNftContract {
* @property total_price - URI of NFT image associated with this owner
* @property transaction - Object containing transaction_hash and block_hash
*/
// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface ApiNftLastSale {
event_timestamp: string;
total_price: string;
Expand All @@ -109,6 +118,9 @@ export interface ApiNftLastSale {
* @property profile_img_url - URI of NFT image associated with this owner
* @property address - The owner address
*/
// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface ApiNftCreator {
user: { username: string };
profile_img_url: string;
Expand All @@ -123,6 +135,9 @@ export interface ApiNftCreator {
* @property chainId - Current chain ID
* @property selectedAddress - Vault selected address
*/
// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface NftDetectionConfig extends BaseConfig {
interval: number;
chainId: Hex;
Expand Down
6 changes: 6 additions & 0 deletions packages/assets-controllers/src/TokenBalancesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export { BN };
* @property interval - Polling interval used to fetch new token balances
* @property tokens - List of tokens to track balances for
*/
// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface TokenBalancesConfig extends BaseConfig {
interval: number;
tokens: Token[];
Expand All @@ -29,6 +32,9 @@ export interface TokenBalancesConfig extends BaseConfig {
* Token balances controller state
* @property contractBalances - Hash of token contract addresses to balances
*/
// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface TokenBalancesState extends BaseState {
contractBalances: { [address: string]: BN };
}
Expand Down
3 changes: 3 additions & 0 deletions packages/assets-controllers/src/TokenDetectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const DEFAULT_INTERVAL = 180000;
* @property isDetectionEnabledFromPreferences - Boolean to track if detection is enabled from PreferencesController
* @property isDetectionEnabledForNetwork - Boolean to track if detected is enabled for current network
*/
// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface TokenDetectionConfig extends BaseConfig {
interval: number;
selectedAddress: string;
Expand Down
24 changes: 24 additions & 0 deletions packages/assets-controllers/src/TokenRatesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import type { TokensState } from './TokensController';
*
* CoinGecko API response representation
*/
// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface CoinGeckoResponse {
[address: string]: {
[currency: string]: number;
Expand All @@ -29,6 +32,9 @@ export interface CoinGeckoResponse {
*
* CoinGecko supported platform API representation
*/
// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface CoinGeckoPlatform {
id: string;
chain_identifier: null | number;
Expand All @@ -45,6 +51,9 @@ export interface CoinGeckoPlatform {
* @property symbol - Symbol of the token
* @property image - Image of the token, url or bit32 image
*/
// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface Token {
address: string;
decimals: number;
Expand All @@ -66,6 +75,9 @@ export interface Token {
* @property tokens - List of tokens to track exchange rates for
* @property threshold - Threshold to invalidate the supportedChains
*/
// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface TokenRatesConfig extends BaseConfig {
interval: number;
nativeCurrency: string;
Expand All @@ -76,15 +88,24 @@ export interface TokenRatesConfig extends BaseConfig {
threshold: number;
}

// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface ContractExchangeRates {
[address: string]: number | undefined;
}

// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface SupportedChainsCache {
timestamp: number;
data: CoinGeckoPlatform[] | null;
}

// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface SupportedVsCurrenciesCache {
timestamp: number;
data: string[];
Expand All @@ -102,6 +123,9 @@ enum PollState {
* @property contractExchangeRates - Hash of token contract addresses to exchange rates
* @property supportedChains - Cached chain data
*/
// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface TokenRatesState extends BaseState {
contractExchangeRates: ContractExchangeRates;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/assets-controllers/src/TokensController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ import type { Token } from './TokenRatesController';
* Tokens controller configuration
* @property selectedAddress - Vault selected address
*/
// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface TokensConfig extends BaseConfig {
selectedAddress: string;
chainId: Hex;
Expand Down Expand Up @@ -85,6 +88,9 @@ type SuggestedAssetMeta = {
* @property allIgnoredTokens - Object containing hidden/ignored tokens by network and account
* @property allDetectedTokens - Object containing tokens detected with non-zero balances
*/
// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface TokensState extends BaseState {
tokens: Token[];
ignoredTokens: string[];
Expand Down
6 changes: 6 additions & 0 deletions packages/base-controller/src/BaseController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export type Listener<T> = (state: T) => void;
* Base controller configuration
* @property disabled - Determines if this controller is enabled
*/
// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface BaseConfig {
disabled?: boolean;
}
Expand All @@ -19,6 +22,9 @@ export interface BaseConfig {
* Base state representation
* @property name - Unique name for this controller
*/
// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface BaseState {
name?: string;
}
Expand Down
3 changes: 3 additions & 0 deletions packages/base-controller/src/BaseControllerV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export type StateMetadata<T extends Record<string, Json>> = {
* identifiable), or is set to a function that returns an anonymized
* representation of this state.
*/
// This interface was created before this ESLint rule was added.
// Convert to a `type` in a future major version.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface StatePropertyMetadata<T extends Json> {
persist: boolean | StateDeriver<T>;
anonymous: boolean | StateDeriver<T>;
Expand Down
10 changes: 6 additions & 4 deletions packages/composable-controller/src/ComposableController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ class FooController extends BaseControllerV2<

// Mock BaseController classes

interface BarControllerState extends BaseState {
type BarControllerState = BaseState & {
bar: string;
}
};

class BarController extends BaseController<never, BarControllerState> {
defaultState = {
bar: 'bar',
Expand All @@ -80,9 +81,10 @@ class BarController extends BaseController<never, BarControllerState> {
}
}

interface BazControllerState extends BaseState {
type BazControllerState = BaseState & {
baz: string;
}
};

class BazController extends BaseController<never, BazControllerState> {
defaultState = {
baz: 'baz',
Expand Down
Loading

0 comments on commit c864e48

Please sign in to comment.