Skip to content

Commit 1b7fe14

Browse files
committed
[eprh] Remove NoUnusedOptOutDirectives (facebook#34703)
This rule was a leftover from a while ago and doesn't actually lint anything useful. Specifically, you get a lint error if you try to opt out a component that isn't already bailing out. If there's a bailout the compiler already safely skips over it, so adding `'use no memo'` there is unnecessary. Fixes facebook#31407 --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34703). * __->__ facebook#34703 * facebook#34700 DiffTrain build for [19f65ff](facebook@19f65ff)
1 parent f2fed1b commit 1b7fe14

37 files changed

+136
-167
lines changed

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

Lines changed: 44 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -54198,20 +54198,6 @@ function getFlowSuppressions(sourceCode) {
5419854198
}
5419954199
return results;
5420054200
}
54201-
function filterUnusedOptOutDirectives(directives) {
54202-
const results = [];
54203-
for (const directive of directives) {
54204-
if (OPT_OUT_DIRECTIVES.has(directive.value.value) &&
54205-
directive.loc != null) {
54206-
results.push({
54207-
loc: directive.loc,
54208-
directive: directive.value.value,
54209-
range: [directive.start, directive.end],
54210-
});
54211-
}
54212-
}
54213-
return results;
54214-
}
5421554201
function runReactCompilerImpl({ sourceCode, filename, userOpts, }) {
5421654202
var _a, _b;
5421754203
const options = parsePluginOptions(Object.assign(Object.assign(Object.assign({}, COMPILER_OPTIONS), userOpts), { environment: Object.assign(Object.assign({}, COMPILER_OPTIONS.environment), userOpts.environment) }));
@@ -54220,7 +54206,6 @@ function runReactCompilerImpl({ sourceCode, filename, userOpts, }) {
5422054206
filename,
5422154207
userOpts,
5422254208
flowSuppressions: [],
54223-
unusedOptOutDirectives: [],
5422454209
events: [],
5422554210
};
5422654211
const userLogger = options.logger;
@@ -54275,21 +54260,6 @@ function runReactCompilerImpl({ sourceCode, filename, userOpts, }) {
5427554260
configFile: false,
5427654261
babelrc: false,
5427754262
});
54278-
if (results.events.filter(e => e.kind === 'CompileError').length === 0) {
54279-
core$1.traverse(babelAST, {
54280-
FunctionDeclaration(path) {
54281-
results.unusedOptOutDirectives.push(...filterUnusedOptOutDirectives(path.node.body.directives));
54282-
},
54283-
ArrowFunctionExpression(path) {
54284-
if (path.node.body.type === 'BlockStatement') {
54285-
results.unusedOptOutDirectives.push(...filterUnusedOptOutDirectives(path.node.body.directives));
54286-
}
54287-
},
54288-
FunctionExpression(path) {
54289-
results.unusedOptOutDirectives.push(...filterUnusedOptOutDirectives(path.node.body.directives));
54290-
},
54291-
});
54292-
}
5429354263
}
5429454264
catch (err) {
5429554265
}
@@ -54459,53 +54429,31 @@ function makeRule(rule) {
5445954429
create,
5446054430
};
5446154431
}
54462-
const NoUnusedDirectivesRule = {
54463-
meta: {
54464-
type: 'suggestion',
54465-
docs: {
54466-
recommended: true,
54467-
},
54468-
fixable: 'code',
54469-
hasSuggestions: true,
54470-
schema: [{ type: 'object', additionalProperties: true }],
54471-
},
54472-
create(context) {
54473-
const results = getReactCompilerResult(context);
54474-
for (const directive of results.unusedOptOutDirectives) {
54475-
context.report({
54476-
message: `Unused '${directive.directive}' directive`,
54477-
loc: directive.loc,
54478-
suggest: [
54479-
{
54480-
desc: 'Remove the directive',
54481-
fix(fixer) {
54482-
return fixer.removeRange(directive.range);
54483-
},
54484-
},
54485-
],
54486-
});
54487-
}
54488-
return {};
54489-
},
54490-
};
5449154432
const allRules = LintRules.reduce((acc, rule) => {
5449254433
acc[rule.name] = { rule: makeRule(rule), severity: rule.severity };
5449354434
return acc;
54494-
}, {
54495-
'no-unused-directives': {
54496-
rule: NoUnusedDirectivesRule,
54497-
severity: ErrorSeverity.Error,
54498-
},
54499-
});
54500-
LintRules.filter(rule => rule.recommended).reduce((acc, rule) => {
54435+
}, {});
54436+
const recommendedRules = LintRules.filter(rule => rule.recommended).reduce((acc, rule) => {
5450154437
acc[rule.name] = { rule: makeRule(rule), severity: rule.severity };
5450254438
return acc;
54503-
}, {
54504-
'no-unused-directives': {
54505-
rule: NoUnusedDirectivesRule,
54506-
severity: ErrorSeverity.Error,
54507-
},
54508-
});
54439+
}, {});
54440+
function mapErrorSeverityToESlint(severity) {
54441+
switch (severity) {
54442+
case ErrorSeverity.Error: {
54443+
return 'error';
54444+
}
54445+
case ErrorSeverity.Warning: {
54446+
return 'warn';
54447+
}
54448+
case ErrorSeverity.Hint:
54449+
case ErrorSeverity.Off: {
54450+
return 'off';
54451+
}
54452+
default: {
54453+
assertExhaustive(severity, `Unhandled severity: ${severity}`);
54454+
}
54455+
}
54456+
}
5450954457

5451054458
var assert_1;
5451154459
var hasRequiredAssert;
@@ -57793,42 +57741,57 @@ function last(array) {
5779357741
}
5779457742

5779557743
const rules = Object.assign({ 'exhaustive-deps': rule$1, 'rules-of-hooks': rule }, Object.fromEntries(Object.entries(allRules).map(([name, config]) => [name, config.rule])));
57796-
const ruleConfigs = {
57744+
const basicRuleConfigs = {
5779757745
'react-hooks/rules-of-hooks': 'error',
5779857746
'react-hooks/exhaustive-deps': 'warn',
5779957747
};
57748+
const compilerRuleConfigs = Object.fromEntries(Object.entries(recommendedRules).map(([name, ruleConfig]) => {
57749+
return [
57750+
`react-hooks/${name}`,
57751+
mapErrorSeverityToESlint(ruleConfig.severity),
57752+
];
57753+
}));
57754+
const allRuleConfigs = Object.assign(Object.assign({}, basicRuleConfigs), compilerRuleConfigs);
5780057755
const plugin = {
5780157756
meta: {
5780257757
name: 'eslint-plugin-react-hooks',
5780357758
},
57804-
configs: {},
5780557759
rules,
57760+
configs: {},
5780657761
};
5780757762
Object.assign(plugin.configs, {
5780857763
'recommended-legacy': {
5780957764
plugins: ['react-hooks'],
57810-
rules: ruleConfigs,
57765+
rules: basicRuleConfigs,
57766+
},
57767+
'recommended-latest-legacy': {
57768+
plugins: ['react-hooks'],
57769+
rules: allRuleConfigs,
5781157770
},
5781257771
'flat/recommended': [
5781357772
{
5781457773
plugins: {
5781557774
'react-hooks': plugin,
5781657775
},
57817-
rules: ruleConfigs,
57776+
rules: basicRuleConfigs,
5781857777
},
5781957778
],
5782057779
'recommended-latest': [
5782157780
{
5782257781
plugins: {
5782357782
'react-hooks': plugin,
5782457783
},
57825-
rules: ruleConfigs,
57784+
rules: allRuleConfigs,
57785+
},
57786+
],
57787+
recommended: [
57788+
{
57789+
plugins: {
57790+
'react-hooks': plugin,
57791+
},
57792+
rules: basicRuleConfigs,
5782657793
},
5782757794
],
57828-
recommended: {
57829-
plugins: ['react-hooks'],
57830-
rules: ruleConfigs,
57831-
},
5783257795
});
5783357796

5783457797
module.exports = plugin;

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2e68dc76a41165d16b35d6eb2e7bf13aafed9aef
1+
19f65ff179d377ff0c9284704dff2fce370745be
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2e68dc76a41165d16b35d6eb2e7bf13aafed9aef
1+
19f65ff179d377ff0c9284704dff2fce370745be

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-2e68dc76-20251002";
1461+
exports.version = "19.3.0-www-classic-19f65ff1-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-2e68dc76-20251002";
1461+
exports.version = "19.3.0-www-modern-19f65ff1-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-2e68dc76-20251002";
607+
exports.version = "19.3.0-www-classic-19f65ff1-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-2e68dc76-20251002";
607+
exports.version = "19.3.0-www-modern-19f65ff1-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-2e68dc76-20251002";
611+
exports.version = "19.3.0-www-classic-19f65ff1-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-2e68dc76-20251002";
611+
exports.version = "19.3.0-www-modern-19f65ff1-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-2e68dc76-20251002",
20306+
version: "19.3.0-www-classic-19f65ff1-20251002",
2030720307
rendererPackageName: "react-art",
2030820308
currentDispatcherRef: ReactSharedInternals,
20309-
reconcilerVersion: "19.3.0-www-classic-2e68dc76-20251002"
20309+
reconcilerVersion: "19.3.0-www-classic-19f65ff1-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-2e68dc76-20251002";
20344+
exports.version = "19.3.0-www-classic-19f65ff1-20251002";
2034520345
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
2034620346
"function" ===
2034720347
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)