From 160caae6f49007f152b0e4db422ef2f02c98d6c8 Mon Sep 17 00:00:00 2001 From: Zhi Wang Date: Thu, 6 Aug 2026 18:43:19 +0930 Subject: [PATCH] TCS-12: Shim eslint-plugin-react, drop react-hooks shim for ESLint v10 eslint-plugin-react ------------------- eslint-plugin-react 7.37.5 (the latest release) does not support ESLint v10. A consumer project on ESLint v10 that imports eslintConfigs.react crashes with: Error while loading rule 'react/display-name': contextOrFilename.getFilename is not a function The plugin calls context.getFilename() when resolving the React version installed in the consumer project, reached only because src/index.js sets settings.react.version to 'detect'. getFilename() was deprecated in ESLint 8.40 in favour of context.filename and removed entirely in v10. Wrap the plugin with fixupPluginRules from @eslint/compat (^2.0.5), which shims the removed context methods onto their modern equivalents. This keeps 'detect' working, so each consumer's real React version is still used rather than a hardcoded literal. eslint-plugin-react-hooks ------------------------- Remove the fixupPluginRules shim around eslint-plugin-react-hooks and use hooksPlugin.configs.flat.recommended instead. Flat config support landed in eslint-plugin-react-hooks 7.0.0 and the installed range is ^7.1.1, so neither the shim nor its "doesn't support flat configs yet" comment applies any more. The applied rule set is unchanged (16 rules, identical severities), so this has no effect on consumers. --- src/index.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index 899f49a..89bb8f5 100644 --- a/src/index.js +++ b/src/index.js @@ -63,13 +63,18 @@ const base = [ const react = [ ...base, - reactPlugin.configs.flat.recommended, - jsxA11yPlugin.flatConfigs.recommended, - // `react-hooks` plugin doesn't support "flat configs" yet so it has to be wrapped in the compatibility layer { - plugins: { 'react-hooks': fixupPluginRules(hooksPlugin) }, - rules: hooksPlugin.configs.recommended.rules, + // `eslint-plugin-react` (7.37.5, the latest release) calls the removed + // `context.getFilename()` API when resolving the React version, which throws + // "Error while loading rule 'react/display-name'" on ESLint 10 whenever + // `settings.react.version` is 'detect'. Wrapping the plugin with fixupPluginRules + // restores the legacy context methods, so version detection keeps working. + // Replace this object with `reactPlugin.configs.flat.recommended` once the plugin supports ESLint 10. + ...reactPlugin.configs.flat.recommended, + plugins: { react: fixupPluginRules(reactPlugin) }, }, + jsxA11yPlugin.flatConfigs.recommended, + hooksPlugin.configs.flat.recommended, { settings: { react: { version: 'detect' } }, rules: {