From 68ce5dfe3af7d3f689875aaf5566c4f43b7917f3 Mon Sep 17 00:00:00 2001 From: Ulisses Ferreira Date: Thu, 27 Aug 2026 10:25:14 +0100 Subject: [PATCH] chore: ban TypeScript enums via lint rule and convert enum in create-package script Add an ESLint no-restricted-syntax rule banning TSEnumDeclaration, and convert the MonorepoFiles and Placeholders enums in scripts/create-package to as const objects with derived union types. --- eslint.config.mjs | 5 +++++ scripts/create-package/constants.ts | 28 ++++++++++++++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 2ecded431..81f39389a 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -161,6 +161,11 @@ const config = createConfig([ typescript, ]), ...NO_CONTROLLER_STATE_CHANGE_SELECTOR_OBJECTS, + { + selector: 'TSEnumDeclaration', + message: + "Don't use enums. There are a number of reasons why they are problematic, but the most important is that TypeScript treats them nominally, not structurally, and this can cause unexpected breaking changes. Instead, use an object + type, an array + type, or just a type. Learn more here: https://github.com/MetaMask/eslint-config/issues/417", + }, ], }, }, diff --git a/scripts/create-package/constants.ts b/scripts/create-package/constants.ts index cf8992ee0..dcf79cfc0 100644 --- a/scripts/create-package/constants.ts +++ b/scripts/create-package/constants.ts @@ -1,20 +1,24 @@ /** * The monorepo files that need to be parsed or modified. */ -export enum MonorepoFiles { - PackageJson = 'package.json', - TsConfig = 'tsconfig.json', - TsConfigBuild = 'tsconfig.build.json', -} +export const MonorepoFiles = { + PackageJson: 'package.json', + TsConfig: 'tsconfig.json', + TsConfigBuild: 'tsconfig.build.json', +} as const; + +export type MonorepoFiles = (typeof MonorepoFiles)[keyof typeof MonorepoFiles]; /** * Placeholder values in package template files that need to be replaced with * actual values corresponding to the new package. */ -export enum Placeholders { - CurrentYear = 'CURRENT_YEAR', - NodeVersions = 'NODE_VERSIONS', - PackageName = 'PACKAGE_NAME', - PackageDescription = 'PACKAGE_DESCRIPTION', - PackageDirectoryName = 'PACKAGE_DIRECTORY_NAME', -} +export const Placeholders = { + CurrentYear: 'CURRENT_YEAR', + NodeVersions: 'NODE_VERSIONS', + PackageName: 'PACKAGE_NAME', + PackageDescription: 'PACKAGE_DESCRIPTION', + PackageDirectoryName: 'PACKAGE_DIRECTORY_NAME', +} as const; + +export type Placeholders = (typeof Placeholders)[keyof typeof Placeholders];