From 9ce30d70b2805d56f9f30cbfb33c8ef15a9693bf Mon Sep 17 00:00:00 2001 From: Rel1cx Date: Tue, 14 Oct 2025 17:23:33 +0800 Subject: [PATCH] Remove transform utils and simplify ESLint plugin export --- packages/plugins/eslint-plugin/src/index.ts | 42 +++++++++++-------- .../plugins/eslint-plugin/src/utils/index.ts | 3 -- .../eslint-plugin/src/utils/pad-keys-left.ts | 11 ----- .../eslint-plugin/src/utils/transform-keys.ts | 24 ----------- .../eslint-plugin/src/utils/type-of.ts | 12 ------ 5 files changed, 24 insertions(+), 68 deletions(-) delete mode 100644 packages/plugins/eslint-plugin/src/utils/index.ts delete mode 100644 packages/plugins/eslint-plugin/src/utils/pad-keys-left.ts delete mode 100644 packages/plugins/eslint-plugin/src/utils/transform-keys.ts delete mode 100644 packages/plugins/eslint-plugin/src/utils/type-of.ts diff --git a/packages/plugins/eslint-plugin/src/index.ts b/packages/plugins/eslint-plugin/src/index.ts index c0db0e7135..21546f0299 100644 --- a/packages/plugins/eslint-plugin/src/index.ts +++ b/packages/plugins/eslint-plugin/src/index.ts @@ -1,10 +1,6 @@ import { name, version } from "../package.json"; -import type { CompatiblePlugin } from "@eslint-react/shared"; -import reactDom from "eslint-plugin-react-dom"; -import reactHooksExtra from "eslint-plugin-react-hooks-extra"; -import reactNamingConvention from "eslint-plugin-react-naming-convention"; -import reactWebApi from "eslint-plugin-react-web-api"; +import type { CompatibleConfig, CompatiblePlugin } from "@eslint-react/shared"; import react from "eslint-plugin-react-x"; import * as allConfig from "./configs/all"; @@ -24,24 +20,29 @@ import * as strictTypescriptConfig from "./configs/strict-typescript"; import * as webApiConfig from "./configs/web-api"; import * as xConfig from "./configs/x"; -import { padKeysLeft } from "./utils"; +type ConfigName = + | "all" + | "disable-conflict-eslint-plugin-react" + | "disable-dom" + | "disable-type-checked" + | "disable-web-api" + | "dom" + | "no-deprecated" + | "off" + | "recommended" + | "recommended-type-checked" + | "recommended-typescript" + | "strict" + | "strict-type-checked" + | "strict-typescript" + | "web-api" + | "x"; -const plugin: CompatiblePlugin = { +const plugin: CompatiblePlugin & { configs: Record } = { meta: { name, version, }, - rules: { - ...react.rules, - ...padKeysLeft(reactDom.rules, "dom/"), - ...padKeysLeft(reactWebApi.rules, "web-api/"), - ...padKeysLeft(reactHooksExtra.rules, "hooks-extra/"), - ...padKeysLeft(reactNamingConvention.rules, "naming-convention/"), - }, -}; - -export default { - ...plugin, configs: { /** * Enable all applicable rules from this plugin @@ -110,4 +111,9 @@ export default { */ ["x"]: xConfig, }, + rules: { + ...react.rules, + }, }; + +export default plugin; diff --git a/packages/plugins/eslint-plugin/src/utils/index.ts b/packages/plugins/eslint-plugin/src/utils/index.ts deleted file mode 100644 index e99679f578..0000000000 --- a/packages/plugins/eslint-plugin/src/utils/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from "./pad-keys-left"; -export * from "./transform-keys"; -export * from "./type-of"; diff --git a/packages/plugins/eslint-plugin/src/utils/pad-keys-left.ts b/packages/plugins/eslint-plugin/src/utils/pad-keys-left.ts deleted file mode 100644 index ac2874fdf7..0000000000 --- a/packages/plugins/eslint-plugin/src/utils/pad-keys-left.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { transformKeys } from "./transform-keys"; - -export type PadKeysLeft = A extends [] ? A - : { [K in keyof A as `${B}${Extract}`]: A[K] }; - -export function padKeysLeft( - obj: A, - left: B, -): PadKeysLeft { - return transformKeys(obj, (key) => `${left}${key}`) as never; -} diff --git a/packages/plugins/eslint-plugin/src/utils/transform-keys.ts b/packages/plugins/eslint-plugin/src/utils/transform-keys.ts deleted file mode 100644 index a0b1860e2c..0000000000 --- a/packages/plugins/eslint-plugin/src/utils/transform-keys.ts +++ /dev/null @@ -1,24 +0,0 @@ -// Copied from https://github.com/gustavoguichard/string-ts/blob/9dd444f03fdfa225f1643e6f1f8c18f9480224bb/src/utils/object-keys/transform-keys.ts#L12 - -import { typeOf } from "./type-of"; - -/** - * This function is used to shallowly transform the keys of an object. - * It will only be transformed at runtime, so it's not type safe. - * @param obj the object to transform. - * @param transform the function to transform the keys from string to string. - * @returns the transformed object. - * @example transformKeys({ 'foo-bar': { 'fizz-buzz': true } }, camelCase) - * // { fooBar: { 'fizz-buzz': true } } - */ -export function transformKeys(obj: T, transform: (s: string) => string): T { - if (typeOf(obj) !== "object") { - return obj; - } - - const res = {} as T; - for (const key in obj) { - res[transform(key) as keyof T] = obj[key]; - } - return res; -} diff --git a/packages/plugins/eslint-plugin/src/utils/type-of.ts b/packages/plugins/eslint-plugin/src/utils/type-of.ts deleted file mode 100644 index db6cc68e2d..0000000000 --- a/packages/plugins/eslint-plugin/src/utils/type-of.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * This is an enhanced version of the typeof operator to check the type of more complex values. - * In this case we just mind about arrays and objects. We can add more on demand. - * @param t the value to be checked - * @returns the type of the value - */ -export function typeOf(t: unknown) { - return Object.prototype.toString - .call(t) - .replace(/^\[object (.+)\]$/, "$1") - .toLowerCase() as "array" | "object" | (string & {}); -}