Skip to content

Commit 1332041

Browse files
committed
[eprh] Fix recommended config for flat config compatibility (#34700)
Previously, the `recommended` config used the legacy ESLint format (plugins as an array of strings). This causes errors when used with ESLint v9's `defineConfig()` helper. This was following [eslint's own docs](https://eslint.org/docs/latest/extend/plugins#backwards-compatibility-for-legacy-configs): > With this approach, both configuration systems recognize "recommended". The old config system uses the recommended key while the current config system uses the flat/recommended key. The defineConfig() helper first looks at the recommended key, and if that is not in the correct format, it looks for the flat/recommended key. This allows you an upgrade path if you’d later like to rename flat/recommended to recommended when you no longer need to support the old config system. However, [`isLegacyConfig()`](https://github.com/eslint/rewrite/blob/main/packages/config-helpers/src/define-config.js#L73-L81) (also see [`eslintrcKeys`](https://github.com/eslint/rewrite/blob/main/packages/config-helpers/src/define-config.js#L24-L35)) function doesn't check for the `plugins` key, so our config was incorrectly treated as flat config despite being in legacy format. This PR fixes the issue, along with a few other fixes combined: 1. Convert `recommended` to flat config format 2. Separate basic rules (exhaustive-deps, rules-of-hooks) from compiler rules 3. Add `recommended-latest-legacy` config for non-flat config users who want all recommended rules (including compiler rules) 4. Adding more types for the exported config Our shipped presets in 6.x.x will essentially be: - `recommended-legacy`: legacy (non-flat), with basic rules only - `recommended-latest-legacy`: legacy (non-flat), all rules (basic + compiler) - `flat/recommended`: flat, basic rules only (now the same as recommended, but to avoid making a breaking change we'll just keep it around in 6.x.x) - `recommended-latest`: flat, all rules (basic + compiler) - `recommended`: flat, basic rules only In the next breaking release 7.x.x, we will collapse down the presets into three: - `recommended-legacy`: all recommended rules - `recommended`: all recommended rules - `recommended-experimental`: all recommended rules + new bleeding edge experimental rules Closes #34679 --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34700). * #34703 * __->__ #34700 DiffTrain build for [26b177b](26b177b)
1 parent ebb0c7f commit 1332041

35 files changed

Lines changed: 110 additions & 97 deletions

compiled/eslint-plugin-react-hooks/index.js

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57810,44 +57810,57 @@ function last(array) {
5781057810
}
5781157811

5781257812
const rules = Object.assign({ 'exhaustive-deps': rule$1, 'rules-of-hooks': rule }, Object.fromEntries(Object.entries(allRules).map(([name, config]) => [name, config.rule])));
57813-
const ruleConfigs = Object.assign({ 'react-hooks/rules-of-hooks': 'error', 'react-hooks/exhaustive-deps': 'warn' }, Object.fromEntries(Object.entries(recommendedRules).map(([name, ruleConfig]) => {
57813+
const basicRuleConfigs = {
57814+
'react-hooks/rules-of-hooks': 'error',
57815+
'react-hooks/exhaustive-deps': 'warn',
57816+
};
57817+
const compilerRuleConfigs = Object.fromEntries(Object.entries(recommendedRules).map(([name, ruleConfig]) => {
5781457818
return [
57815-
'react-hooks/' + name,
57819+
`react-hooks/${name}`,
5781657820
mapErrorSeverityToESlint(ruleConfig.severity),
5781757821
];
57818-
})));
57822+
}));
57823+
const allRuleConfigs = Object.assign(Object.assign({}, basicRuleConfigs), compilerRuleConfigs);
5781957824
const plugin = {
5782057825
meta: {
5782157826
name: 'eslint-plugin-react-hooks',
5782257827
},
57823-
configs: {},
5782457828
rules,
57829+
configs: {},
5782557830
};
5782657831
Object.assign(plugin.configs, {
5782757832
'recommended-legacy': {
5782857833
plugins: ['react-hooks'],
57829-
rules: ruleConfigs,
57834+
rules: basicRuleConfigs,
57835+
},
57836+
'recommended-latest-legacy': {
57837+
plugins: ['react-hooks'],
57838+
rules: allRuleConfigs,
5783057839
},
5783157840
'flat/recommended': [
5783257841
{
5783357842
plugins: {
5783457843
'react-hooks': plugin,
5783557844
},
57836-
rules: ruleConfigs,
57845+
rules: basicRuleConfigs,
5783757846
},
5783857847
],
5783957848
'recommended-latest': [
5784057849
{
5784157850
plugins: {
5784257851
'react-hooks': plugin,
5784357852
},
57844-
rules: ruleConfigs,
57853+
rules: allRuleConfigs,
57854+
},
57855+
],
57856+
recommended: [
57857+
{
57858+
plugins: {
57859+
'react-hooks': plugin,
57860+
},
57861+
rules: basicRuleConfigs,
5784557862
},
5784657863
],
57847-
recommended: {
57848-
plugins: ['react-hooks'],
57849-
rules: ruleConfigs,
57850-
},
5785157864
});
5785257865

5785357866
module.exports = plugin;

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
056a586928fe1b6186d3693743ac7019ce39cb7b
1+
26b177bc5e1d287c60c50fc1e185b2fb398488a0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
056a586928fe1b6186d3693743ac7019ce39cb7b
1+
26b177bc5e1d287c60c50fc1e185b2fb398488a0

compiled/facebook-www/React-dev.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,7 @@ __DEV__ &&
14581458
exports.useTransition = function () {
14591459
return resolveDispatcher().useTransition();
14601460
};
1461-
exports.version = "19.3.0-www-classic-056a5869-20251002";
1461+
exports.version = "19.3.0-www-classic-26b177bc-20251002";
14621462
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
14631463
"function" ===
14641464
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-dev.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,7 @@ __DEV__ &&
14581458
exports.useTransition = function () {
14591459
return resolveDispatcher().useTransition();
14601460
};
1461-
exports.version = "19.3.0-www-modern-056a5869-20251002";
1461+
exports.version = "19.3.0-www-modern-26b177bc-20251002";
14621462
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
14631463
"function" ===
14641464
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-prod.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,4 +604,4 @@ exports.useSyncExternalStore = function (
604604
exports.useTransition = function () {
605605
return ReactSharedInternals.H.useTransition();
606606
};
607-
exports.version = "19.3.0-www-classic-056a5869-20251002";
607+
exports.version = "19.3.0-www-classic-26b177bc-20251002";

compiled/facebook-www/React-prod.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,4 +604,4 @@ exports.useSyncExternalStore = function (
604604
exports.useTransition = function () {
605605
return ReactSharedInternals.H.useTransition();
606606
};
607-
exports.version = "19.3.0-www-modern-056a5869-20251002";
607+
exports.version = "19.3.0-www-modern-26b177bc-20251002";

compiled/facebook-www/React-profiling.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ exports.useSyncExternalStore = function (
608608
exports.useTransition = function () {
609609
return ReactSharedInternals.H.useTransition();
610610
};
611-
exports.version = "19.3.0-www-classic-056a5869-20251002";
611+
exports.version = "19.3.0-www-classic-26b177bc-20251002";
612612
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
613613
"function" ===
614614
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-profiling.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ exports.useSyncExternalStore = function (
608608
exports.useTransition = function () {
609609
return ReactSharedInternals.H.useTransition();
610610
};
611-
exports.version = "19.3.0-www-modern-056a5869-20251002";
611+
exports.version = "19.3.0-www-modern-26b177bc-20251002";
612612
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
613613
"function" ===
614614
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/ReactART-dev.classic.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20303,10 +20303,10 @@ __DEV__ &&
2030320303
(function () {
2030420304
var internals = {
2030520305
bundleType: 1,
20306-
version: "19.3.0-www-classic-056a5869-20251002",
20306+
version: "19.3.0-www-classic-26b177bc-20251002",
2030720307
rendererPackageName: "react-art",
2030820308
currentDispatcherRef: ReactSharedInternals,
20309-
reconcilerVersion: "19.3.0-www-classic-056a5869-20251002"
20309+
reconcilerVersion: "19.3.0-www-classic-26b177bc-20251002"
2031020310
};
2031120311
internals.overrideHookState = overrideHookState;
2031220312
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -20341,7 +20341,7 @@ __DEV__ &&
2034120341
exports.Shape = Shape;
2034220342
exports.Surface = Surface;
2034320343
exports.Text = Text;
20344-
exports.version = "19.3.0-www-classic-056a5869-20251002";
20344+
exports.version = "19.3.0-www-classic-26b177bc-20251002";
2034520345
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
2034620346
"function" ===
2034720347
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)