From 7a4ac2da5a474c6cd6be7ae46359fb3aa1db7316 Mon Sep 17 00:00:00 2001 From: MorikawaSouma Date: Wed, 18 Mar 2026 12:47:25 +0800 Subject: [PATCH] fix(eslint-plugin-react-hooks): sync version with package.json The version in packages/eslint-plugin-react-hooks/src/index.ts was hardcoded as a string, violating the Single Source of Truth (SSOT) principle. This change: - Uses createRequire to dynamically load the version from package.json - Updates tsconfig.json to support ES2020 features (import.meta) - Adds resolveJsonModule for future JSON import support The runtime version now always matches the published package metadata without requiring manual synchronization during releases. Fixes #35722 --- packages/eslint-plugin-react-hooks/src/index.ts | 9 ++++++++- packages/eslint-plugin-react-hooks/tsconfig.json | 5 +++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/eslint-plugin-react-hooks/src/index.ts b/packages/eslint-plugin-react-hooks/src/index.ts index 924299d89894..b2478a0af5c7 100644 --- a/packages/eslint-plugin-react-hooks/src/index.ts +++ b/packages/eslint-plugin-react-hooks/src/index.ts @@ -6,6 +6,8 @@ */ import type {Linter, Rule} from 'eslint'; +import {createRequire} from 'module'; + import ExhaustiveDeps from './rules/ExhaustiveDeps'; import { allRules, @@ -15,6 +17,11 @@ import { } from './shared/ReactCompiler'; import RulesOfHooks from './rules/RulesOfHooks'; +// Use createRequire to load package.json version at runtime +// This ensures the version is always in sync with package.json +const require = createRequire(import.meta.url); +const pkg = require('../package.json'); + const rules = { 'exhaustive-deps': ExhaustiveDeps, 'rules-of-hooks': RulesOfHooks, @@ -80,7 +87,7 @@ const configs = { const plugin = { meta: { name: 'eslint-plugin-react-hooks', - version: '7.0.0', + version: pkg.version, }, rules, configs, diff --git a/packages/eslint-plugin-react-hooks/tsconfig.json b/packages/eslint-plugin-react-hooks/tsconfig.json index c5d8847f1ec4..b6c33cc6c0b7 100644 --- a/packages/eslint-plugin-react-hooks/tsconfig.json +++ b/packages/eslint-plugin-react-hooks/tsconfig.json @@ -1,12 +1,13 @@ { "extends": "@tsconfig/strictest/tsconfig.json", "compilerOptions": { - "module": "ES2015", - "target": "ES2015", + "module": "ES2020", + "target": "ES2020", "moduleResolution": "Bundler", "lib": ["ES2020", "dom"], "sourceMap": false, "types": ["estree-jsx", "node"], + "resolveJsonModule": true, "downlevelIteration": true, "paths": { "babel-plugin-react-compiler": ["../../compiler/packages/babel-plugin-react-compiler/src"]