Skip to content

Commit 19f65ff

Browse files
authored
[eprh] Remove NoUnusedOptOutDirectives (#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#31407 --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34703). * __->__ #34703 * #34700
1 parent 26b177b commit 19f65ff

5 files changed

Lines changed: 14 additions & 262 deletions

File tree

‎compiler/packages/eslint-plugin-react-compiler/__tests__/NoUnusedDirectivesRule-test.ts‎

Lines changed: 0 additions & 58 deletions
This file was deleted.

‎compiler/packages/eslint-plugin-react-compiler/src/rules/ReactCompilerRule.ts‎

Lines changed: 8 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -161,69 +161,21 @@ function makeRule(rule: LintRule): Rule.RuleModule {
161161
};
162162
}
163163

164-
exportconstNoUnusedDirectivesRule: Rule.RuleModule={
165-
meta: {
166-
type: 'suggestion',
167-
docs: {
168-
recommended: true,
169-
},
170-
fixable: 'code',
171-
hasSuggestions: true,
172-
// validation is done at runtime with zod
173-
schema: [{type: 'object',additionalProperties: true}],
174-
},
175-
create(context: Rule.RuleContext): Rule.RuleListener{
176-
constresults=getReactCompilerResult(context);
177-
178-
for(constdirectiveofresults.unusedOptOutDirectives){
179-
context.report({
180-
message: `Unused '${directive.directive}' directive`,
181-
loc: directive.loc,
182-
suggest: [
183-
{
184-
desc: 'Remove the directive',
185-
fix(fixer): Rule.Fix{
186-
returnfixer.removeRange(directive.range);
187-
},
188-
},
189-
],
190-
});
191-
}
192-
return{};
193-
},
194-
};
195-
196164
typeRulesConfig={
197165
[name: string]: {rule: Rule.RuleModule;severity: ErrorSeverity};
198166
};
199167

200-
exportconstallRules: RulesConfig=LintRules.reduce(
201-
(acc,rule)=>{
202-
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
203-
returnacc;
204-
},
205-
{
206-
'no-unused-directives': {
207-
rule: NoUnusedDirectivesRule,
208-
severity: ErrorSeverity.Error,
209-
},
210-
}asRulesConfig,
211-
);
168+
exportconstallRules: RulesConfig=LintRules.reduce((acc,rule)=>{
169+
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
170+
returnacc;
171+
},{}asRulesConfig);
212172

213173
exportconstrecommendedRules: RulesConfig=LintRules.filter(
214174
rule=>rule.recommended,
215-
).reduce(
216-
(acc,rule)=>{
217-
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
218-
returnacc;
219-
},
220-
{
221-
'no-unused-directives': {
222-
rule: NoUnusedDirectivesRule,
223-
severity: ErrorSeverity.Error,
224-
},
225-
}asRulesConfig,
226-
);
175+
).reduce((acc,rule)=>{
176+
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
177+
returnacc;
178+
},{}asRulesConfig);
227179

228180
exportfunctionmapErrorSeverityToESlint(
229181
severity: ErrorSeverity,

‎compiler/packages/eslint-plugin-react-compiler/src/shared/RunReactCompiler.ts‎

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import{transformFromAstSync,traverse}from'@babel/core';
8+
import{transformFromAstSync}from'@babel/core';
99
import{parseasbabelParse}from'@babel/parser';
10-
import{Directive,File}from'@babel/types';
10+
import{File}from'@babel/types';
1111
// @ts-expect-error: no types available
1212
importPluginProposalPrivateMethodsfrom'@babel/plugin-proposal-private-methods';
1313
importBabelPluginReactCompiler,{
1414
parsePluginOptions,
1515
validateEnvironmentConfig,
16-
OPT_OUT_DIRECTIVES,
1716
typePluginOptions,
1817
}from'babel-plugin-react-compiler/src';
1918
import{Logger,LoggerEvent}from'babel-plugin-react-compiler/src/Entrypoint';
2019
importtype{SourceCode}from'eslint';
21-
import{SourceLocation}from'estree';
2220
// @ts-expect-error: no types available
2321
import*asHermesParserfrom'hermes-parser';
2422
import{isDeepStrictEqual}from'util';
@@ -45,17 +43,11 @@ const COMPILER_OPTIONS: PluginOptions = {
4543
}),
4644
};
4745

48-
exporttypeUnusedOptOutDirective={
49-
loc: SourceLocation;
50-
range: [number,number];
51-
directive: string;
52-
};
5346
exporttypeRunCacheEntry={
5447
sourceCode: string;
5548
filename: string;
5649
userOpts: PluginOptions;
5750
flowSuppressions: Array<{line: number;code: string}>;
58-
unusedOptOutDirectives: Array<UnusedOptOutDirective>;
5951
events: Array<LoggerEvent>;
6052
};
6153

@@ -87,25 +79,6 @@ function getFlowSuppressions(
8779
returnresults;
8880
}
8981

90-
functionfilterUnusedOptOutDirectives(
91-
directives: ReadonlyArray<Directive>,
92-
): Array<UnusedOptOutDirective>{
93-
constresults: Array<UnusedOptOutDirective>=[];
94-
for(constdirectiveofdirectives){
95-
if(
96-
OPT_OUT_DIRECTIVES.has(directive.value.value)&&
97-
directive.loc!=null
98-
){
99-
results.push({
100-
loc: directive.loc,
101-
directive: directive.value.value,
102-
range: [directive.start!,directive.end!],
103-
});
104-
}
105-
}
106-
returnresults;
107-
}
108-
10982
functionrunReactCompilerImpl({
11083
sourceCode,
11184
filename,
@@ -125,7 +98,6 @@ function runReactCompilerImpl({
12598
filename,
12699
userOpts,
127100
flowSuppressions: [],
128-
unusedOptOutDirectives: [],
129101
events: [],
130102
};
131103
constuserLogger: Logger|null=options.logger;
@@ -181,29 +153,6 @@ function runReactCompilerImpl({
181153
configFile: false,
182154
babelrc: false,
183155
});
184-
185-
if(results.events.filter(e=>e.kind==='CompileError').length===0){
186-
traverse(babelAST,{
187-
FunctionDeclaration(path){
188-
path.node;
189-
results.unusedOptOutDirectives.push(
190-
...filterUnusedOptOutDirectives(path.node.body.directives),
191-
);
192-
},
193-
ArrowFunctionExpression(path){
194-
if(path.node.body.type==='BlockStatement'){
195-
results.unusedOptOutDirectives.push(
196-
...filterUnusedOptOutDirectives(path.node.body.directives),
197-
);
198-
}
199-
},
200-
FunctionExpression(path){
201-
results.unusedOptOutDirectives.push(
202-
...filterUnusedOptOutDirectives(path.node.body.directives),
203-
);
204-
},
205-
});
206-
}
207156
}catch(err){
208157
/* errors handled by injected logger */
209158
}

‎packages/eslint-plugin-react-hooks/src/shared/ReactCompiler.ts‎

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -160,38 +160,6 @@ function makeRule(rule: LintRule): Rule.RuleModule {
160160
};
161161
}
162162

163-
exportconstNoUnusedDirectivesRule: Rule.RuleModule={
164-
meta: {
165-
type: 'suggestion',
166-
docs: {
167-
recommended: true,
168-
},
169-
fixable: 'code',
170-
hasSuggestions: true,
171-
// validation is done at runtime with zod
172-
schema: [{type: 'object',additionalProperties: true}],
173-
},
174-
create(context: Rule.RuleContext): Rule.RuleListener{
175-
constresults=getReactCompilerResult(context);
176-
177-
for(constdirectiveofresults.unusedOptOutDirectives){
178-
context.report({
179-
message: `Unused '${directive.directive}' directive`,
180-
loc: directive.loc,
181-
suggest: [
182-
{
183-
desc: 'Remove the directive',
184-
fix(fixer): Rule.Fix{
185-
returnfixer.removeRange(directive.range);
186-
},
187-
},
188-
],
189-
});
190-
}
191-
return{};
192-
},
193-
};
194-
195163
typeRulesConfig={
196164
[name: string]: {rule: Rule.RuleModule;severity: ErrorSeverity};
197165
};
@@ -201,12 +169,7 @@ export const allRules: RulesConfig = LintRules.reduce(
201169
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
202170
returnacc;
203171
},
204-
{
205-
'no-unused-directives': {
206-
rule: NoUnusedDirectivesRule,
207-
severity: ErrorSeverity.Error,
208-
},
209-
}asRulesConfig,
172+
{}asRulesConfig,
210173
);
211174

212175
exportconstrecommendedRules: RulesConfig=LintRules.filter(
@@ -216,12 +179,7 @@ export const recommendedRules: RulesConfig = LintRules.filter(
216179
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
217180
returnacc;
218181
},
219-
{
220-
'no-unused-directives': {
221-
rule: NoUnusedDirectivesRule,
222-
severity: ErrorSeverity.Error,
223-
},
224-
}asRulesConfig,
182+
{}asRulesConfig,
225183
);
226184

227185
exportfunctionmapErrorSeverityToESlint(

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
[eprh] Remove NoUnusedOptOutDirectives (#34703) · react/react@19f65ff · GitHub
Skip to content

Commit 19f65ff

Browse files
authored
[eprh] Remove NoUnusedOptOutDirectives (#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#31407 --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34703). * __->__ #34703 * #34700
1 parent 26b177b commit 19f65ff

5 files changed

Lines changed: 14 additions & 262 deletions

File tree

‎compiler/packages/eslint-plugin-react-compiler/__tests__/NoUnusedDirectivesRule-test.ts‎

Lines changed: 0 additions & 58 deletions
This file was deleted.

‎compiler/packages/eslint-plugin-react-compiler/src/rules/ReactCompilerRule.ts‎

Lines changed: 8 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -161,69 +161,21 @@ function makeRule(rule: LintRule): Rule.RuleModule {
161161
};
162162
}
163163

164-
exportconstNoUnusedDirectivesRule: Rule.RuleModule={
165-
meta: {
166-
type: 'suggestion',
167-
docs: {
168-
recommended: true,
169-
},
170-
fixable: 'code',
171-
hasSuggestions: true,
172-
// validation is done at runtime with zod
173-
schema: [{type: 'object',additionalProperties: true}],
174-
},
175-
create(context: Rule.RuleContext): Rule.RuleListener{
176-
constresults=getReactCompilerResult(context);
177-
178-
for(constdirectiveofresults.unusedOptOutDirectives){
179-
context.report({
180-
message: `Unused '${directive.directive}' directive`,
181-
loc: directive.loc,
182-
suggest: [
183-
{
184-
desc: 'Remove the directive',
185-
fix(fixer): Rule.Fix{
186-
returnfixer.removeRange(directive.range);
187-
},
188-
},
189-
],
190-
});
191-
}
192-
return{};
193-
},
194-
};
195-
196164
typeRulesConfig={
197165
[name: string]: {rule: Rule.RuleModule;severity: ErrorSeverity};
198166
};
199167

200-
exportconstallRules: RulesConfig=LintRules.reduce(
201-
(acc,rule)=>{
202-
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
203-
returnacc;
204-
},
205-
{
206-
'no-unused-directives': {
207-
rule: NoUnusedDirectivesRule,
208-
severity: ErrorSeverity.Error,
209-
},
210-
}asRulesConfig,
211-
);
168+
exportconstallRules: RulesConfig=LintRules.reduce((acc,rule)=>{
169+
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
170+
returnacc;
171+
},{}asRulesConfig);
212172

213173
exportconstrecommendedRules: RulesConfig=LintRules.filter(
214174
rule=>rule.recommended,
215-
).reduce(
216-
(acc,rule)=>{
217-
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
218-
returnacc;
219-
},
220-
{
221-
'no-unused-directives': {
222-
rule: NoUnusedDirectivesRule,
223-
severity: ErrorSeverity.Error,
224-
},
225-
}asRulesConfig,
226-
);
175+
).reduce((acc,rule)=>{
176+
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
177+
returnacc;
178+
},{}asRulesConfig);
227179

228180
exportfunctionmapErrorSeverityToESlint(
229181
severity: ErrorSeverity,

‎compiler/packages/eslint-plugin-react-compiler/src/shared/RunReactCompiler.ts‎

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import{transformFromAstSync,traverse}from'@babel/core';
8+
import{transformFromAstSync}from'@babel/core';
99
import{parseasbabelParse}from'@babel/parser';
10-
import{Directive,File}from'@babel/types';
10+
import{File}from'@babel/types';
1111
// @ts-expect-error: no types available
1212
importPluginProposalPrivateMethodsfrom'@babel/plugin-proposal-private-methods';
1313
importBabelPluginReactCompiler,{
1414
parsePluginOptions,
1515
validateEnvironmentConfig,
16-
OPT_OUT_DIRECTIVES,
1716
typePluginOptions,
1817
}from'babel-plugin-react-compiler/src';
1918
import{Logger,LoggerEvent}from'babel-plugin-react-compiler/src/Entrypoint';
2019
importtype{SourceCode}from'eslint';
21-
import{SourceLocation}from'estree';
2220
// @ts-expect-error: no types available
2321
import*asHermesParserfrom'hermes-parser';
2422
import{isDeepStrictEqual}from'util';
@@ -45,17 +43,11 @@ const COMPILER_OPTIONS: PluginOptions = {
4543
}),
4644
};
4745

48-
exporttypeUnusedOptOutDirective={
49-
loc: SourceLocation;
50-
range: [number,number];
51-
directive: string;
52-
};
5346
exporttypeRunCacheEntry={
5447
sourceCode: string;
5548
filename: string;
5649
userOpts: PluginOptions;
5750
flowSuppressions: Array<{line: number;code: string}>;
58-
unusedOptOutDirectives: Array<UnusedOptOutDirective>;
5951
events: Array<LoggerEvent>;
6052
};
6153

@@ -87,25 +79,6 @@ function getFlowSuppressions(
8779
returnresults;
8880
}
8981

90-
functionfilterUnusedOptOutDirectives(
91-
directives: ReadonlyArray<Directive>,
92-
): Array<UnusedOptOutDirective>{
93-
constresults: Array<UnusedOptOutDirective>=[];
94-
for(constdirectiveofdirectives){
95-
if(
96-
OPT_OUT_DIRECTIVES.has(directive.value.value)&&
97-
directive.loc!=null
98-
){
99-
results.push({
100-
loc: directive.loc,
101-
directive: directive.value.value,
102-
range: [directive.start!,directive.end!],
103-
});
104-
}
105-
}
106-
returnresults;
107-
}
108-
10982
functionrunReactCompilerImpl({
11083
sourceCode,
11184
filename,
@@ -125,7 +98,6 @@ function runReactCompilerImpl({
12598
filename,
12699
userOpts,
127100
flowSuppressions: [],
128-
unusedOptOutDirectives: [],
129101
events: [],
130102
};
131103
constuserLogger: Logger|null=options.logger;
@@ -181,29 +153,6 @@ function runReactCompilerImpl({
181153
configFile: false,
182154
babelrc: false,
183155
});
184-
185-
if(results.events.filter(e=>e.kind==='CompileError').length===0){
186-
traverse(babelAST,{
187-
FunctionDeclaration(path){
188-
path.node;
189-
results.unusedOptOutDirectives.push(
190-
...filterUnusedOptOutDirectives(path.node.body.directives),
191-
);
192-
},
193-
ArrowFunctionExpression(path){
194-
if(path.node.body.type==='BlockStatement'){
195-
results.unusedOptOutDirectives.push(
196-
...filterUnusedOptOutDirectives(path.node.body.directives),
197-
);
198-
}
199-
},
200-
FunctionExpression(path){
201-
results.unusedOptOutDirectives.push(
202-
...filterUnusedOptOutDirectives(path.node.body.directives),
203-
);
204-
},
205-
});
206-
}
207156
}catch(err){
208157
/* errors handled by injected logger */
209158
}

‎packages/eslint-plugin-react-hooks/src/shared/ReactCompiler.ts‎

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -160,38 +160,6 @@ function makeRule(rule: LintRule): Rule.RuleModule {
160160
};
161161
}
162162

163-
exportconstNoUnusedDirectivesRule: Rule.RuleModule={
164-
meta: {
165-
type: 'suggestion',
166-
docs: {
167-
recommended: true,
168-
},
169-
fixable: 'code',
170-
hasSuggestions: true,
171-
// validation is done at runtime with zod
172-
schema: [{type: 'object',additionalProperties: true}],
173-
},
174-
create(context: Rule.RuleContext): Rule.RuleListener{
175-
constresults=getReactCompilerResult(context);
176-
177-
for(constdirectiveofresults.unusedOptOutDirectives){
178-
context.report({
179-
message: `Unused '${directive.directive}' directive`,
180-
loc: directive.loc,
181-
suggest: [
182-
{
183-
desc: 'Remove the directive',
184-
fix(fixer): Rule.Fix{
185-
returnfixer.removeRange(directive.range);
186-
},
187-
},
188-
],
189-
});
190-
}
191-
return{};
192-
},
193-
};
194-
195163
typeRulesConfig={
196164
[name: string]: {rule: Rule.RuleModule;severity: ErrorSeverity};
197165
};
@@ -201,12 +169,7 @@ export const allRules: RulesConfig = LintRules.reduce(
201169
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
202170
returnacc;
203171
},
204-
{
205-
'no-unused-directives': {
206-
rule: NoUnusedDirectivesRule,
207-
severity: ErrorSeverity.Error,
208-
},
209-
}asRulesConfig,
172+
{}asRulesConfig,
210173
);
211174

212175
exportconstrecommendedRules: RulesConfig=LintRules.filter(
@@ -216,12 +179,7 @@ export const recommendedRules: RulesConfig = LintRules.filter(
216179
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
217180
returnacc;
218181
},
219-
{
220-
'no-unused-directives': {
221-
rule: NoUnusedDirectivesRule,
222-
severity: ErrorSeverity.Error,
223-
},
224-
}asRulesConfig,
182+
{}asRulesConfig,
225183
);
226184

227185
exportfunctionmapErrorSeverityToESlint(

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [eprh] Remove NoUnusedOptOutDirectives (#34703) · react/react@19f65ff · GitHub
Skip to content

Commit 19f65ff

Browse files
authored
[eprh] Remove NoUnusedOptOutDirectives (#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#31407 --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34703). * __->__ #34703 * #34700
1 parent 26b177b commit 19f65ff

5 files changed

Lines changed: 14 additions & 262 deletions

File tree

‎compiler/packages/eslint-plugin-react-compiler/__tests__/NoUnusedDirectivesRule-test.ts‎

Lines changed: 0 additions & 58 deletions
This file was deleted.

‎compiler/packages/eslint-plugin-react-compiler/src/rules/ReactCompilerRule.ts‎

Lines changed: 8 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -161,69 +161,21 @@ function makeRule(rule: LintRule): Rule.RuleModule {
161161
};
162162
}
163163

164-
exportconstNoUnusedDirectivesRule: Rule.RuleModule={
165-
meta: {
166-
type: 'suggestion',
167-
docs: {
168-
recommended: true,
169-
},
170-
fixable: 'code',
171-
hasSuggestions: true,
172-
// validation is done at runtime with zod
173-
schema: [{type: 'object',additionalProperties: true}],
174-
},
175-
create(context: Rule.RuleContext): Rule.RuleListener{
176-
constresults=getReactCompilerResult(context);
177-
178-
for(constdirectiveofresults.unusedOptOutDirectives){
179-
context.report({
180-
message: `Unused '${directive.directive}' directive`,
181-
loc: directive.loc,
182-
suggest: [
183-
{
184-
desc: 'Remove the directive',
185-
fix(fixer): Rule.Fix{
186-
returnfixer.removeRange(directive.range);
187-
},
188-
},
189-
],
190-
});
191-
}
192-
return{};
193-
},
194-
};
195-
196164
typeRulesConfig={
197165
[name: string]: {rule: Rule.RuleModule;severity: ErrorSeverity};
198166
};
199167

200-
exportconstallRules: RulesConfig=LintRules.reduce(
201-
(acc,rule)=>{
202-
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
203-
returnacc;
204-
},
205-
{
206-
'no-unused-directives': {
207-
rule: NoUnusedDirectivesRule,
208-
severity: ErrorSeverity.Error,
209-
},
210-
}asRulesConfig,
211-
);
168+
exportconstallRules: RulesConfig=LintRules.reduce((acc,rule)=>{
169+
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
170+
returnacc;
171+
},{}asRulesConfig);
212172

213173
exportconstrecommendedRules: RulesConfig=LintRules.filter(
214174
rule=>rule.recommended,
215-
).reduce(
216-
(acc,rule)=>{
217-
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
218-
returnacc;
219-
},
220-
{
221-
'no-unused-directives': {
222-
rule: NoUnusedDirectivesRule,
223-
severity: ErrorSeverity.Error,
224-
},
225-
}asRulesConfig,
226-
);
175+
).reduce((acc,rule)=>{
176+
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
177+
returnacc;
178+
},{}asRulesConfig);
227179

228180
exportfunctionmapErrorSeverityToESlint(
229181
severity: ErrorSeverity,

‎compiler/packages/eslint-plugin-react-compiler/src/shared/RunReactCompiler.ts‎

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import{transformFromAstSync,traverse}from'@babel/core';
8+
import{transformFromAstSync}from'@babel/core';
99
import{parseasbabelParse}from'@babel/parser';
10-
import{Directive,File}from'@babel/types';
10+
import{File}from'@babel/types';
1111
// @ts-expect-error: no types available
1212
importPluginProposalPrivateMethodsfrom'@babel/plugin-proposal-private-methods';
1313
importBabelPluginReactCompiler,{
1414
parsePluginOptions,
1515
validateEnvironmentConfig,
16-
OPT_OUT_DIRECTIVES,
1716
typePluginOptions,
1817
}from'babel-plugin-react-compiler/src';
1918
import{Logger,LoggerEvent}from'babel-plugin-react-compiler/src/Entrypoint';
2019
importtype{SourceCode}from'eslint';
21-
import{SourceLocation}from'estree';
2220
// @ts-expect-error: no types available
2321
import*asHermesParserfrom'hermes-parser';
2422
import{isDeepStrictEqual}from'util';
@@ -45,17 +43,11 @@ const COMPILER_OPTIONS: PluginOptions = {
4543
}),
4644
};
4745

48-
exporttypeUnusedOptOutDirective={
49-
loc: SourceLocation;
50-
range: [number,number];
51-
directive: string;
52-
};
5346
exporttypeRunCacheEntry={
5447
sourceCode: string;
5548
filename: string;
5649
userOpts: PluginOptions;
5750
flowSuppressions: Array<{line: number;code: string}>;
58-
unusedOptOutDirectives: Array<UnusedOptOutDirective>;
5951
events: Array<LoggerEvent>;
6052
};
6153

@@ -87,25 +79,6 @@ function getFlowSuppressions(
8779
returnresults;
8880
}
8981

90-
functionfilterUnusedOptOutDirectives(
91-
directives: ReadonlyArray<Directive>,
92-
): Array<UnusedOptOutDirective>{
93-
constresults: Array<UnusedOptOutDirective>=[];
94-
for(constdirectiveofdirectives){
95-
if(
96-
OPT_OUT_DIRECTIVES.has(directive.value.value)&&
97-
directive.loc!=null
98-
){
99-
results.push({
100-
loc: directive.loc,
101-
directive: directive.value.value,
102-
range: [directive.start!,directive.end!],
103-
});
104-
}
105-
}
106-
returnresults;
107-
}
108-
10982
functionrunReactCompilerImpl({
11083
sourceCode,
11184
filename,
@@ -125,7 +98,6 @@ function runReactCompilerImpl({
12598
filename,
12699
userOpts,
127100
flowSuppressions: [],
128-
unusedOptOutDirectives: [],
129101
events: [],
130102
};
131103
constuserLogger: Logger|null=options.logger;
@@ -181,29 +153,6 @@ function runReactCompilerImpl({
181153
configFile: false,
182154
babelrc: false,
183155
});
184-
185-
if(results.events.filter(e=>e.kind==='CompileError').length===0){
186-
traverse(babelAST,{
187-
FunctionDeclaration(path){
188-
path.node;
189-
results.unusedOptOutDirectives.push(
190-
...filterUnusedOptOutDirectives(path.node.body.directives),
191-
);
192-
},
193-
ArrowFunctionExpression(path){
194-
if(path.node.body.type==='BlockStatement'){
195-
results.unusedOptOutDirectives.push(
196-
...filterUnusedOptOutDirectives(path.node.body.directives),
197-
);
198-
}
199-
},
200-
FunctionExpression(path){
201-
results.unusedOptOutDirectives.push(
202-
...filterUnusedOptOutDirectives(path.node.body.directives),
203-
);
204-
},
205-
});
206-
}
207156
}catch(err){
208157
/* errors handled by injected logger */
209158
}

‎packages/eslint-plugin-react-hooks/src/shared/ReactCompiler.ts‎

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -160,38 +160,6 @@ function makeRule(rule: LintRule): Rule.RuleModule {
160160
};
161161
}
162162

163-
exportconstNoUnusedDirectivesRule: Rule.RuleModule={
164-
meta: {
165-
type: 'suggestion',
166-
docs: {
167-
recommended: true,
168-
},
169-
fixable: 'code',
170-
hasSuggestions: true,
171-
// validation is done at runtime with zod
172-
schema: [{type: 'object',additionalProperties: true}],
173-
},
174-
create(context: Rule.RuleContext): Rule.RuleListener{
175-
constresults=getReactCompilerResult(context);
176-
177-
for(constdirectiveofresults.unusedOptOutDirectives){
178-
context.report({
179-
message: `Unused '${directive.directive}' directive`,
180-
loc: directive.loc,
181-
suggest: [
182-
{
183-
desc: 'Remove the directive',
184-
fix(fixer): Rule.Fix{
185-
returnfixer.removeRange(directive.range);
186-
},
187-
},
188-
],
189-
});
190-
}
191-
return{};
192-
},
193-
};
194-
195163
typeRulesConfig={
196164
[name: string]: {rule: Rule.RuleModule;severity: ErrorSeverity};
197165
};
@@ -201,12 +169,7 @@ export const allRules: RulesConfig = LintRules.reduce(
201169
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
202170
returnacc;
203171
},
204-
{
205-
'no-unused-directives': {
206-
rule: NoUnusedDirectivesRule,
207-
severity: ErrorSeverity.Error,
208-
},
209-
}asRulesConfig,
172+
{}asRulesConfig,
210173
);
211174

212175
exportconstrecommendedRules: RulesConfig=LintRules.filter(
@@ -216,12 +179,7 @@ export const recommendedRules: RulesConfig = LintRules.filter(
216179
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
217180
returnacc;
218181
},
219-
{
220-
'no-unused-directives': {
221-
rule: NoUnusedDirectivesRule,
222-
severity: ErrorSeverity.Error,
223-
},
224-
}asRulesConfig,
182+
{}asRulesConfig,
225183
);
226184

227185
exportfunctionmapErrorSeverityToESlint(

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [eprh] Remove NoUnusedOptOutDirectives (#34703) · react/react@19f65ff · GitHub
Skip to content

Commit 19f65ff

Browse files
authored
[eprh] Remove NoUnusedOptOutDirectives (#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#31407 --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34703). * __->__ #34703 * #34700
1 parent 26b177b commit 19f65ff

5 files changed

Lines changed: 14 additions & 262 deletions

File tree

‎compiler/packages/eslint-plugin-react-compiler/__tests__/NoUnusedDirectivesRule-test.ts‎

Lines changed: 0 additions & 58 deletions
This file was deleted.

‎compiler/packages/eslint-plugin-react-compiler/src/rules/ReactCompilerRule.ts‎

Lines changed: 8 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -161,69 +161,21 @@ function makeRule(rule: LintRule): Rule.RuleModule {
161161
};
162162
}
163163

164-
exportconstNoUnusedDirectivesRule: Rule.RuleModule={
165-
meta: {
166-
type: 'suggestion',
167-
docs: {
168-
recommended: true,
169-
},
170-
fixable: 'code',
171-
hasSuggestions: true,
172-
// validation is done at runtime with zod
173-
schema: [{type: 'object',additionalProperties: true}],
174-
},
175-
create(context: Rule.RuleContext): Rule.RuleListener{
176-
constresults=getReactCompilerResult(context);
177-
178-
for(constdirectiveofresults.unusedOptOutDirectives){
179-
context.report({
180-
message: `Unused '${directive.directive}' directive`,
181-
loc: directive.loc,
182-
suggest: [
183-
{
184-
desc: 'Remove the directive',
185-
fix(fixer): Rule.Fix{
186-
returnfixer.removeRange(directive.range);
187-
},
188-
},
189-
],
190-
});
191-
}
192-
return{};
193-
},
194-
};
195-
196164
typeRulesConfig={
197165
[name: string]: {rule: Rule.RuleModule;severity: ErrorSeverity};
198166
};
199167

200-
exportconstallRules: RulesConfig=LintRules.reduce(
201-
(acc,rule)=>{
202-
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
203-
returnacc;
204-
},
205-
{
206-
'no-unused-directives': {
207-
rule: NoUnusedDirectivesRule,
208-
severity: ErrorSeverity.Error,
209-
},
210-
}asRulesConfig,
211-
);
168+
exportconstallRules: RulesConfig=LintRules.reduce((acc,rule)=>{
169+
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
170+
returnacc;
171+
},{}asRulesConfig);
212172

213173
exportconstrecommendedRules: RulesConfig=LintRules.filter(
214174
rule=>rule.recommended,
215-
).reduce(
216-
(acc,rule)=>{
217-
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
218-
returnacc;
219-
},
220-
{
221-
'no-unused-directives': {
222-
rule: NoUnusedDirectivesRule,
223-
severity: ErrorSeverity.Error,
224-
},
225-
}asRulesConfig,
226-
);
175+
).reduce((acc,rule)=>{
176+
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
177+
returnacc;
178+
},{}asRulesConfig);
227179

228180
exportfunctionmapErrorSeverityToESlint(
229181
severity: ErrorSeverity,

‎compiler/packages/eslint-plugin-react-compiler/src/shared/RunReactCompiler.ts‎

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import{transformFromAstSync,traverse}from'@babel/core';
8+
import{transformFromAstSync}from'@babel/core';
99
import{parseasbabelParse}from'@babel/parser';
10-
import{Directive,File}from'@babel/types';
10+
import{File}from'@babel/types';
1111
// @ts-expect-error: no types available
1212
importPluginProposalPrivateMethodsfrom'@babel/plugin-proposal-private-methods';
1313
importBabelPluginReactCompiler,{
1414
parsePluginOptions,
1515
validateEnvironmentConfig,
16-
OPT_OUT_DIRECTIVES,
1716
typePluginOptions,
1817
}from'babel-plugin-react-compiler/src';
1918
import{Logger,LoggerEvent}from'babel-plugin-react-compiler/src/Entrypoint';
2019
importtype{SourceCode}from'eslint';
21-
import{SourceLocation}from'estree';
2220
// @ts-expect-error: no types available
2321
import*asHermesParserfrom'hermes-parser';
2422
import{isDeepStrictEqual}from'util';
@@ -45,17 +43,11 @@ const COMPILER_OPTIONS: PluginOptions = {
4543
}),
4644
};
4745

48-
exporttypeUnusedOptOutDirective={
49-
loc: SourceLocation;
50-
range: [number,number];
51-
directive: string;
52-
};
5346
exporttypeRunCacheEntry={
5447
sourceCode: string;
5548
filename: string;
5649
userOpts: PluginOptions;
5750
flowSuppressions: Array<{line: number;code: string}>;
58-
unusedOptOutDirectives: Array<UnusedOptOutDirective>;
5951
events: Array<LoggerEvent>;
6052
};
6153

@@ -87,25 +79,6 @@ function getFlowSuppressions(
8779
returnresults;
8880
}
8981

90-
functionfilterUnusedOptOutDirectives(
91-
directives: ReadonlyArray<Directive>,
92-
): Array<UnusedOptOutDirective>{
93-
constresults: Array<UnusedOptOutDirective>=[];
94-
for(constdirectiveofdirectives){
95-
if(
96-
OPT_OUT_DIRECTIVES.has(directive.value.value)&&
97-
directive.loc!=null
98-
){
99-
results.push({
100-
loc: directive.loc,
101-
directive: directive.value.value,
102-
range: [directive.start!,directive.end!],
103-
});
104-
}
105-
}
106-
returnresults;
107-
}
108-
10982
functionrunReactCompilerImpl({
11083
sourceCode,
11184
filename,
@@ -125,7 +98,6 @@ function runReactCompilerImpl({
12598
filename,
12699
userOpts,
127100
flowSuppressions: [],
128-
unusedOptOutDirectives: [],
129101
events: [],
130102
};
131103
constuserLogger: Logger|null=options.logger;
@@ -181,29 +153,6 @@ function runReactCompilerImpl({
181153
configFile: false,
182154
babelrc: false,
183155
});
184-
185-
if(results.events.filter(e=>e.kind==='CompileError').length===0){
186-
traverse(babelAST,{
187-
FunctionDeclaration(path){
188-
path.node;
189-
results.unusedOptOutDirectives.push(
190-
...filterUnusedOptOutDirectives(path.node.body.directives),
191-
);
192-
},
193-
ArrowFunctionExpression(path){
194-
if(path.node.body.type==='BlockStatement'){
195-
results.unusedOptOutDirectives.push(
196-
...filterUnusedOptOutDirectives(path.node.body.directives),
197-
);
198-
}
199-
},
200-
FunctionExpression(path){
201-
results.unusedOptOutDirectives.push(
202-
...filterUnusedOptOutDirectives(path.node.body.directives),
203-
);
204-
},
205-
});
206-
}
207156
}catch(err){
208157
/* errors handled by injected logger */
209158
}

‎packages/eslint-plugin-react-hooks/src/shared/ReactCompiler.ts‎

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -160,38 +160,6 @@ function makeRule(rule: LintRule): Rule.RuleModule {
160160
};
161161
}
162162

163-
exportconstNoUnusedDirectivesRule: Rule.RuleModule={
164-
meta: {
165-
type: 'suggestion',
166-
docs: {
167-
recommended: true,
168-
},
169-
fixable: 'code',
170-
hasSuggestions: true,
171-
// validation is done at runtime with zod
172-
schema: [{type: 'object',additionalProperties: true}],
173-
},
174-
create(context: Rule.RuleContext): Rule.RuleListener{
175-
constresults=getReactCompilerResult(context);
176-
177-
for(constdirectiveofresults.unusedOptOutDirectives){
178-
context.report({
179-
message: `Unused '${directive.directive}' directive`,
180-
loc: directive.loc,
181-
suggest: [
182-
{
183-
desc: 'Remove the directive',
184-
fix(fixer): Rule.Fix{
185-
returnfixer.removeRange(directive.range);
186-
},
187-
},
188-
],
189-
});
190-
}
191-
return{};
192-
},
193-
};
194-
195163
typeRulesConfig={
196164
[name: string]: {rule: Rule.RuleModule;severity: ErrorSeverity};
197165
};
@@ -201,12 +169,7 @@ export const allRules: RulesConfig = LintRules.reduce(
201169
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
202170
returnacc;
203171
},
204-
{
205-
'no-unused-directives': {
206-
rule: NoUnusedDirectivesRule,
207-
severity: ErrorSeverity.Error,
208-
},
209-
}asRulesConfig,
172+
{}asRulesConfig,
210173
);
211174

212175
exportconstrecommendedRules: RulesConfig=LintRules.filter(
@@ -216,12 +179,7 @@ export const recommendedRules: RulesConfig = LintRules.filter(
216179
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
217180
returnacc;
218181
},
219-
{
220-
'no-unused-directives': {
221-
rule: NoUnusedDirectivesRule,
222-
severity: ErrorSeverity.Error,
223-
},
224-
}asRulesConfig,
182+
{}asRulesConfig,
225183
);
226184

227185
exportfunctionmapErrorSeverityToESlint(

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' [eprh] Remove NoUnusedOptOutDirectives (#34703) · react/react@19f65ff · GitHub
Skip to content

Commit 19f65ff

Browse files
authored
[eprh] Remove NoUnusedOptOutDirectives (#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#31407 --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34703). * __->__ #34703 * #34700
1 parent 26b177b commit 19f65ff

5 files changed

Lines changed: 14 additions & 262 deletions

File tree

‎compiler/packages/eslint-plugin-react-compiler/__tests__/NoUnusedDirectivesRule-test.ts‎

Lines changed: 0 additions & 58 deletions
This file was deleted.

‎compiler/packages/eslint-plugin-react-compiler/src/rules/ReactCompilerRule.ts‎

Lines changed: 8 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -161,69 +161,21 @@ function makeRule(rule: LintRule): Rule.RuleModule {
161161
};
162162
}
163163

164-
exportconstNoUnusedDirectivesRule: Rule.RuleModule={
165-
meta: {
166-
type: 'suggestion',
167-
docs: {
168-
recommended: true,
169-
},
170-
fixable: 'code',
171-
hasSuggestions: true,
172-
// validation is done at runtime with zod
173-
schema: [{type: 'object',additionalProperties: true}],
174-
},
175-
create(context: Rule.RuleContext): Rule.RuleListener{
176-
constresults=getReactCompilerResult(context);
177-
178-
for(constdirectiveofresults.unusedOptOutDirectives){
179-
context.report({
180-
message: `Unused '${directive.directive}' directive`,
181-
loc: directive.loc,
182-
suggest: [
183-
{
184-
desc: 'Remove the directive',
185-
fix(fixer): Rule.Fix{
186-
returnfixer.removeRange(directive.range);
187-
},
188-
},
189-
],
190-
});
191-
}
192-
return{};
193-
},
194-
};
195-
196164
typeRulesConfig={
197165
[name: string]: {rule: Rule.RuleModule;severity: ErrorSeverity};
198166
};
199167

200-
exportconstallRules: RulesConfig=LintRules.reduce(
201-
(acc,rule)=>{
202-
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
203-
returnacc;
204-
},
205-
{
206-
'no-unused-directives': {
207-
rule: NoUnusedDirectivesRule,
208-
severity: ErrorSeverity.Error,
209-
},
210-
}asRulesConfig,
211-
);
168+
exportconstallRules: RulesConfig=LintRules.reduce((acc,rule)=>{
169+
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
170+
returnacc;
171+
},{}asRulesConfig);
212172

213173
exportconstrecommendedRules: RulesConfig=LintRules.filter(
214174
rule=>rule.recommended,
215-
).reduce(
216-
(acc,rule)=>{
217-
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
218-
returnacc;
219-
},
220-
{
221-
'no-unused-directives': {
222-
rule: NoUnusedDirectivesRule,
223-
severity: ErrorSeverity.Error,
224-
},
225-
}asRulesConfig,
226-
);
175+
).reduce((acc,rule)=>{
176+
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
177+
returnacc;
178+
},{}asRulesConfig);
227179

228180
exportfunctionmapErrorSeverityToESlint(
229181
severity: ErrorSeverity,

‎compiler/packages/eslint-plugin-react-compiler/src/shared/RunReactCompiler.ts‎

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import{transformFromAstSync,traverse}from'@babel/core';
8+
import{transformFromAstSync}from'@babel/core';
99
import{parseasbabelParse}from'@babel/parser';
10-
import{Directive,File}from'@babel/types';
10+
import{File}from'@babel/types';
1111
// @ts-expect-error: no types available
1212
importPluginProposalPrivateMethodsfrom'@babel/plugin-proposal-private-methods';
1313
importBabelPluginReactCompiler,{
1414
parsePluginOptions,
1515
validateEnvironmentConfig,
16-
OPT_OUT_DIRECTIVES,
1716
typePluginOptions,
1817
}from'babel-plugin-react-compiler/src';
1918
import{Logger,LoggerEvent}from'babel-plugin-react-compiler/src/Entrypoint';
2019
importtype{SourceCode}from'eslint';
21-
import{SourceLocation}from'estree';
2220
// @ts-expect-error: no types available
2321
import*asHermesParserfrom'hermes-parser';
2422
import{isDeepStrictEqual}from'util';
@@ -45,17 +43,11 @@ const COMPILER_OPTIONS: PluginOptions = {
4543
}),
4644
};
4745

48-
exporttypeUnusedOptOutDirective={
49-
loc: SourceLocation;
50-
range: [number,number];
51-
directive: string;
52-
};
5346
exporttypeRunCacheEntry={
5447
sourceCode: string;
5548
filename: string;
5649
userOpts: PluginOptions;
5750
flowSuppressions: Array<{line: number;code: string}>;
58-
unusedOptOutDirectives: Array<UnusedOptOutDirective>;
5951
events: Array<LoggerEvent>;
6052
};
6153

@@ -87,25 +79,6 @@ function getFlowSuppressions(
8779
returnresults;
8880
}
8981

90-
functionfilterUnusedOptOutDirectives(
91-
directives: ReadonlyArray<Directive>,
92-
): Array<UnusedOptOutDirective>{
93-
constresults: Array<UnusedOptOutDirective>=[];
94-
for(constdirectiveofdirectives){
95-
if(
96-
OPT_OUT_DIRECTIVES.has(directive.value.value)&&
97-
directive.loc!=null
98-
){
99-
results.push({
100-
loc: directive.loc,
101-
directive: directive.value.value,
102-
range: [directive.start!,directive.end!],
103-
});
104-
}
105-
}
106-
returnresults;
107-
}
108-
10982
functionrunReactCompilerImpl({
11083
sourceCode,
11184
filename,
@@ -125,7 +98,6 @@ function runReactCompilerImpl({
12598
filename,
12699
userOpts,
127100
flowSuppressions: [],
128-
unusedOptOutDirectives: [],
129101
events: [],
130102
};
131103
constuserLogger: Logger|null=options.logger;
@@ -181,29 +153,6 @@ function runReactCompilerImpl({
181153
configFile: false,
182154
babelrc: false,
183155
});
184-
185-
if(results.events.filter(e=>e.kind==='CompileError').length===0){
186-
traverse(babelAST,{
187-
FunctionDeclaration(path){
188-
path.node;
189-
results.unusedOptOutDirectives.push(
190-
...filterUnusedOptOutDirectives(path.node.body.directives),
191-
);
192-
},
193-
ArrowFunctionExpression(path){
194-
if(path.node.body.type==='BlockStatement'){
195-
results.unusedOptOutDirectives.push(
196-
...filterUnusedOptOutDirectives(path.node.body.directives),
197-
);
198-
}
199-
},
200-
FunctionExpression(path){
201-
results.unusedOptOutDirectives.push(
202-
...filterUnusedOptOutDirectives(path.node.body.directives),
203-
);
204-
},
205-
});
206-
}
207156
}catch(err){
208157
/* errors handled by injected logger */
209158
}

‎packages/eslint-plugin-react-hooks/src/shared/ReactCompiler.ts‎

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -160,38 +160,6 @@ function makeRule(rule: LintRule): Rule.RuleModule {
160160
};
161161
}
162162

163-
exportconstNoUnusedDirectivesRule: Rule.RuleModule={
164-
meta: {
165-
type: 'suggestion',
166-
docs: {
167-
recommended: true,
168-
},
169-
fixable: 'code',
170-
hasSuggestions: true,
171-
// validation is done at runtime with zod
172-
schema: [{type: 'object',additionalProperties: true}],
173-
},
174-
create(context: Rule.RuleContext): Rule.RuleListener{
175-
constresults=getReactCompilerResult(context);
176-
177-
for(constdirectiveofresults.unusedOptOutDirectives){
178-
context.report({
179-
message: `Unused '${directive.directive}' directive`,
180-
loc: directive.loc,
181-
suggest: [
182-
{
183-
desc: 'Remove the directive',
184-
fix(fixer): Rule.Fix{
185-
returnfixer.removeRange(directive.range);
186-
},
187-
},
188-
],
189-
});
190-
}
191-
return{};
192-
},
193-
};
194-
195163
typeRulesConfig={
196164
[name: string]: {rule: Rule.RuleModule;severity: ErrorSeverity};
197165
};
@@ -201,12 +169,7 @@ export const allRules: RulesConfig = LintRules.reduce(
201169
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
202170
returnacc;
203171
},
204-
{
205-
'no-unused-directives': {
206-
rule: NoUnusedDirectivesRule,
207-
severity: ErrorSeverity.Error,
208-
},
209-
}asRulesConfig,
172+
{}asRulesConfig,
210173
);
211174

212175
exportconstrecommendedRules: RulesConfig=LintRules.filter(
@@ -216,12 +179,7 @@ export const recommendedRules: RulesConfig = LintRules.filter(
216179
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
217180
returnacc;
218181
},
219-
{
220-
'no-unused-directives': {
221-
rule: NoUnusedDirectivesRule,
222-
severity: ErrorSeverity.Error,
223-
},
224-
}asRulesConfig,
182+
{}asRulesConfig,
225183
);
226184

227185
exportfunctionmapErrorSeverityToESlint(

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [eprh] Remove NoUnusedOptOutDirectives (#34703) · react/react@19f65ff · GitHub
Skip to content

Commit 19f65ff

Browse files
authored
[eprh] Remove NoUnusedOptOutDirectives (#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#31407 --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34703). * __->__ #34703 * #34700
1 parent 26b177b commit 19f65ff

5 files changed

Lines changed: 14 additions & 262 deletions

File tree

‎compiler/packages/eslint-plugin-react-compiler/__tests__/NoUnusedDirectivesRule-test.ts‎

Lines changed: 0 additions & 58 deletions
This file was deleted.

‎compiler/packages/eslint-plugin-react-compiler/src/rules/ReactCompilerRule.ts‎

Lines changed: 8 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -161,69 +161,21 @@ function makeRule(rule: LintRule): Rule.RuleModule {
161161
};
162162
}
163163

164-
exportconstNoUnusedDirectivesRule: Rule.RuleModule={
165-
meta: {
166-
type: 'suggestion',
167-
docs: {
168-
recommended: true,
169-
},
170-
fixable: 'code',
171-
hasSuggestions: true,
172-
// validation is done at runtime with zod
173-
schema: [{type: 'object',additionalProperties: true}],
174-
},
175-
create(context: Rule.RuleContext): Rule.RuleListener{
176-
constresults=getReactCompilerResult(context);
177-
178-
for(constdirectiveofresults.unusedOptOutDirectives){
179-
context.report({
180-
message: `Unused '${directive.directive}' directive`,
181-
loc: directive.loc,
182-
suggest: [
183-
{
184-
desc: 'Remove the directive',
185-
fix(fixer): Rule.Fix{
186-
returnfixer.removeRange(directive.range);
187-
},
188-
},
189-
],
190-
});
191-
}
192-
return{};
193-
},
194-
};
195-
196164
typeRulesConfig={
197165
[name: string]: {rule: Rule.RuleModule;severity: ErrorSeverity};
198166
};
199167

200-
exportconstallRules: RulesConfig=LintRules.reduce(
201-
(acc,rule)=>{
202-
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
203-
returnacc;
204-
},
205-
{
206-
'no-unused-directives': {
207-
rule: NoUnusedDirectivesRule,
208-
severity: ErrorSeverity.Error,
209-
},
210-
}asRulesConfig,
211-
);
168+
exportconstallRules: RulesConfig=LintRules.reduce((acc,rule)=>{
169+
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
170+
returnacc;
171+
},{}asRulesConfig);
212172

213173
exportconstrecommendedRules: RulesConfig=LintRules.filter(
214174
rule=>rule.recommended,
215-
).reduce(
216-
(acc,rule)=>{
217-
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
218-
returnacc;
219-
},
220-
{
221-
'no-unused-directives': {
222-
rule: NoUnusedDirectivesRule,
223-
severity: ErrorSeverity.Error,
224-
},
225-
}asRulesConfig,
226-
);
175+
).reduce((acc,rule)=>{
176+
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
177+
returnacc;
178+
},{}asRulesConfig);
227179

228180
exportfunctionmapErrorSeverityToESlint(
229181
severity: ErrorSeverity,

‎compiler/packages/eslint-plugin-react-compiler/src/shared/RunReactCompiler.ts‎

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import{transformFromAstSync,traverse}from'@babel/core';
8+
import{transformFromAstSync}from'@babel/core';
99
import{parseasbabelParse}from'@babel/parser';
10-
import{Directive,File}from'@babel/types';
10+
import{File}from'@babel/types';
1111
// @ts-expect-error: no types available
1212
importPluginProposalPrivateMethodsfrom'@babel/plugin-proposal-private-methods';
1313
importBabelPluginReactCompiler,{
1414
parsePluginOptions,
1515
validateEnvironmentConfig,
16-
OPT_OUT_DIRECTIVES,
1716
typePluginOptions,
1817
}from'babel-plugin-react-compiler/src';
1918
import{Logger,LoggerEvent}from'babel-plugin-react-compiler/src/Entrypoint';
2019
importtype{SourceCode}from'eslint';
21-
import{SourceLocation}from'estree';
2220
// @ts-expect-error: no types available
2321
import*asHermesParserfrom'hermes-parser';
2422
import{isDeepStrictEqual}from'util';
@@ -45,17 +43,11 @@ const COMPILER_OPTIONS: PluginOptions = {
4543
}),
4644
};
4745

48-
exporttypeUnusedOptOutDirective={
49-
loc: SourceLocation;
50-
range: [number,number];
51-
directive: string;
52-
};
5346
exporttypeRunCacheEntry={
5447
sourceCode: string;
5548
filename: string;
5649
userOpts: PluginOptions;
5750
flowSuppressions: Array<{line: number;code: string}>;
58-
unusedOptOutDirectives: Array<UnusedOptOutDirective>;
5951
events: Array<LoggerEvent>;
6052
};
6153

@@ -87,25 +79,6 @@ function getFlowSuppressions(
8779
returnresults;
8880
}
8981

90-
functionfilterUnusedOptOutDirectives(
91-
directives: ReadonlyArray<Directive>,
92-
): Array<UnusedOptOutDirective>{
93-
constresults: Array<UnusedOptOutDirective>=[];
94-
for(constdirectiveofdirectives){
95-
if(
96-
OPT_OUT_DIRECTIVES.has(directive.value.value)&&
97-
directive.loc!=null
98-
){
99-
results.push({
100-
loc: directive.loc,
101-
directive: directive.value.value,
102-
range: [directive.start!,directive.end!],
103-
});
104-
}
105-
}
106-
returnresults;
107-
}
108-
10982
functionrunReactCompilerImpl({
11083
sourceCode,
11184
filename,
@@ -125,7 +98,6 @@ function runReactCompilerImpl({
12598
filename,
12699
userOpts,
127100
flowSuppressions: [],
128-
unusedOptOutDirectives: [],
129101
events: [],
130102
};
131103
constuserLogger: Logger|null=options.logger;
@@ -181,29 +153,6 @@ function runReactCompilerImpl({
181153
configFile: false,
182154
babelrc: false,
183155
});
184-
185-
if(results.events.filter(e=>e.kind==='CompileError').length===0){
186-
traverse(babelAST,{
187-
FunctionDeclaration(path){
188-
path.node;
189-
results.unusedOptOutDirectives.push(
190-
...filterUnusedOptOutDirectives(path.node.body.directives),
191-
);
192-
},
193-
ArrowFunctionExpression(path){
194-
if(path.node.body.type==='BlockStatement'){
195-
results.unusedOptOutDirectives.push(
196-
...filterUnusedOptOutDirectives(path.node.body.directives),
197-
);
198-
}
199-
},
200-
FunctionExpression(path){
201-
results.unusedOptOutDirectives.push(
202-
...filterUnusedOptOutDirectives(path.node.body.directives),
203-
);
204-
},
205-
});
206-
}
207156
}catch(err){
208157
/* errors handled by injected logger */
209158
}

‎packages/eslint-plugin-react-hooks/src/shared/ReactCompiler.ts‎

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -160,38 +160,6 @@ function makeRule(rule: LintRule): Rule.RuleModule {
160160
};
161161
}
162162

163-
exportconstNoUnusedDirectivesRule: Rule.RuleModule={
164-
meta: {
165-
type: 'suggestion',
166-
docs: {
167-
recommended: true,
168-
},
169-
fixable: 'code',
170-
hasSuggestions: true,
171-
// validation is done at runtime with zod
172-
schema: [{type: 'object',additionalProperties: true}],
173-
},
174-
create(context: Rule.RuleContext): Rule.RuleListener{
175-
constresults=getReactCompilerResult(context);
176-
177-
for(constdirectiveofresults.unusedOptOutDirectives){
178-
context.report({
179-
message: `Unused '${directive.directive}' directive`,
180-
loc: directive.loc,
181-
suggest: [
182-
{
183-
desc: 'Remove the directive',
184-
fix(fixer): Rule.Fix{
185-
returnfixer.removeRange(directive.range);
186-
},
187-
},
188-
],
189-
});
190-
}
191-
return{};
192-
},
193-
};
194-
195163
typeRulesConfig={
196164
[name: string]: {rule: Rule.RuleModule;severity: ErrorSeverity};
197165
};
@@ -201,12 +169,7 @@ export const allRules: RulesConfig = LintRules.reduce(
201169
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
202170
returnacc;
203171
},
204-
{
205-
'no-unused-directives': {
206-
rule: NoUnusedDirectivesRule,
207-
severity: ErrorSeverity.Error,
208-
},
209-
}asRulesConfig,
172+
{}asRulesConfig,
210173
);
211174

212175
exportconstrecommendedRules: RulesConfig=LintRules.filter(
@@ -216,12 +179,7 @@ export const recommendedRules: RulesConfig = LintRules.filter(
216179
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
217180
returnacc;
218181
},
219-
{
220-
'no-unused-directives': {
221-
rule: NoUnusedDirectivesRule,
222-
severity: ErrorSeverity.Error,
223-
},
224-
}asRulesConfig,
182+
{}asRulesConfig,
225183
);
226184

227185
exportfunctionmapErrorSeverityToESlint(

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [eprh] Remove NoUnusedOptOutDirectives (#34703) · react/react@19f65ff · GitHub
Skip to content

Commit 19f65ff

Browse files
authored
[eprh] Remove NoUnusedOptOutDirectives (#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#31407 --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34703). * __->__ #34703 * #34700
1 parent 26b177b commit 19f65ff

5 files changed

Lines changed: 14 additions & 262 deletions

File tree

‎compiler/packages/eslint-plugin-react-compiler/__tests__/NoUnusedDirectivesRule-test.ts‎

Lines changed: 0 additions & 58 deletions
This file was deleted.

‎compiler/packages/eslint-plugin-react-compiler/src/rules/ReactCompilerRule.ts‎

Lines changed: 8 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -161,69 +161,21 @@ function makeRule(rule: LintRule): Rule.RuleModule {
161161
};
162162
}
163163

164-
exportconstNoUnusedDirectivesRule: Rule.RuleModule={
165-
meta: {
166-
type: 'suggestion',
167-
docs: {
168-
recommended: true,
169-
},
170-
fixable: 'code',
171-
hasSuggestions: true,
172-
// validation is done at runtime with zod
173-
schema: [{type: 'object',additionalProperties: true}],
174-
},
175-
create(context: Rule.RuleContext): Rule.RuleListener{
176-
constresults=getReactCompilerResult(context);
177-
178-
for(constdirectiveofresults.unusedOptOutDirectives){
179-
context.report({
180-
message: `Unused '${directive.directive}' directive`,
181-
loc: directive.loc,
182-
suggest: [
183-
{
184-
desc: 'Remove the directive',
185-
fix(fixer): Rule.Fix{
186-
returnfixer.removeRange(directive.range);
187-
},
188-
},
189-
],
190-
});
191-
}
192-
return{};
193-
},
194-
};
195-
196164
typeRulesConfig={
197165
[name: string]: {rule: Rule.RuleModule;severity: ErrorSeverity};
198166
};
199167

200-
exportconstallRules: RulesConfig=LintRules.reduce(
201-
(acc,rule)=>{
202-
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
203-
returnacc;
204-
},
205-
{
206-
'no-unused-directives': {
207-
rule: NoUnusedDirectivesRule,
208-
severity: ErrorSeverity.Error,
209-
},
210-
}asRulesConfig,
211-
);
168+
exportconstallRules: RulesConfig=LintRules.reduce((acc,rule)=>{
169+
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
170+
returnacc;
171+
},{}asRulesConfig);
212172

213173
exportconstrecommendedRules: RulesConfig=LintRules.filter(
214174
rule=>rule.recommended,
215-
).reduce(
216-
(acc,rule)=>{
217-
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
218-
returnacc;
219-
},
220-
{
221-
'no-unused-directives': {
222-
rule: NoUnusedDirectivesRule,
223-
severity: ErrorSeverity.Error,
224-
},
225-
}asRulesConfig,
226-
);
175+
).reduce((acc,rule)=>{
176+
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
177+
returnacc;
178+
},{}asRulesConfig);
227179

228180
exportfunctionmapErrorSeverityToESlint(
229181
severity: ErrorSeverity,

‎compiler/packages/eslint-plugin-react-compiler/src/shared/RunReactCompiler.ts‎

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import{transformFromAstSync,traverse}from'@babel/core';
8+
import{transformFromAstSync}from'@babel/core';
99
import{parseasbabelParse}from'@babel/parser';
10-
import{Directive,File}from'@babel/types';
10+
import{File}from'@babel/types';
1111
// @ts-expect-error: no types available
1212
importPluginProposalPrivateMethodsfrom'@babel/plugin-proposal-private-methods';
1313
importBabelPluginReactCompiler,{
1414
parsePluginOptions,
1515
validateEnvironmentConfig,
16-
OPT_OUT_DIRECTIVES,
1716
typePluginOptions,
1817
}from'babel-plugin-react-compiler/src';
1918
import{Logger,LoggerEvent}from'babel-plugin-react-compiler/src/Entrypoint';
2019
importtype{SourceCode}from'eslint';
21-
import{SourceLocation}from'estree';
2220
// @ts-expect-error: no types available
2321
import*asHermesParserfrom'hermes-parser';
2422
import{isDeepStrictEqual}from'util';
@@ -45,17 +43,11 @@ const COMPILER_OPTIONS: PluginOptions = {
4543
}),
4644
};
4745

48-
exporttypeUnusedOptOutDirective={
49-
loc: SourceLocation;
50-
range: [number,number];
51-
directive: string;
52-
};
5346
exporttypeRunCacheEntry={
5447
sourceCode: string;
5548
filename: string;
5649
userOpts: PluginOptions;
5750
flowSuppressions: Array<{line: number;code: string}>;
58-
unusedOptOutDirectives: Array<UnusedOptOutDirective>;
5951
events: Array<LoggerEvent>;
6052
};
6153

@@ -87,25 +79,6 @@ function getFlowSuppressions(
8779
returnresults;
8880
}
8981

90-
functionfilterUnusedOptOutDirectives(
91-
directives: ReadonlyArray<Directive>,
92-
): Array<UnusedOptOutDirective>{
93-
constresults: Array<UnusedOptOutDirective>=[];
94-
for(constdirectiveofdirectives){
95-
if(
96-
OPT_OUT_DIRECTIVES.has(directive.value.value)&&
97-
directive.loc!=null
98-
){
99-
results.push({
100-
loc: directive.loc,
101-
directive: directive.value.value,
102-
range: [directive.start!,directive.end!],
103-
});
104-
}
105-
}
106-
returnresults;
107-
}
108-
10982
functionrunReactCompilerImpl({
11083
sourceCode,
11184
filename,
@@ -125,7 +98,6 @@ function runReactCompilerImpl({
12598
filename,
12699
userOpts,
127100
flowSuppressions: [],
128-
unusedOptOutDirectives: [],
129101
events: [],
130102
};
131103
constuserLogger: Logger|null=options.logger;
@@ -181,29 +153,6 @@ function runReactCompilerImpl({
181153
configFile: false,
182154
babelrc: false,
183155
});
184-
185-
if(results.events.filter(e=>e.kind==='CompileError').length===0){
186-
traverse(babelAST,{
187-
FunctionDeclaration(path){
188-
path.node;
189-
results.unusedOptOutDirectives.push(
190-
...filterUnusedOptOutDirectives(path.node.body.directives),
191-
);
192-
},
193-
ArrowFunctionExpression(path){
194-
if(path.node.body.type==='BlockStatement'){
195-
results.unusedOptOutDirectives.push(
196-
...filterUnusedOptOutDirectives(path.node.body.directives),
197-
);
198-
}
199-
},
200-
FunctionExpression(path){
201-
results.unusedOptOutDirectives.push(
202-
...filterUnusedOptOutDirectives(path.node.body.directives),
203-
);
204-
},
205-
});
206-
}
207156
}catch(err){
208157
/* errors handled by injected logger */
209158
}

‎packages/eslint-plugin-react-hooks/src/shared/ReactCompiler.ts‎

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -160,38 +160,6 @@ function makeRule(rule: LintRule): Rule.RuleModule {
160160
};
161161
}
162162

163-
exportconstNoUnusedDirectivesRule: Rule.RuleModule={
164-
meta: {
165-
type: 'suggestion',
166-
docs: {
167-
recommended: true,
168-
},
169-
fixable: 'code',
170-
hasSuggestions: true,
171-
// validation is done at runtime with zod
172-
schema: [{type: 'object',additionalProperties: true}],
173-
},
174-
create(context: Rule.RuleContext): Rule.RuleListener{
175-
constresults=getReactCompilerResult(context);
176-
177-
for(constdirectiveofresults.unusedOptOutDirectives){
178-
context.report({
179-
message: `Unused '${directive.directive}' directive`,
180-
loc: directive.loc,
181-
suggest: [
182-
{
183-
desc: 'Remove the directive',
184-
fix(fixer): Rule.Fix{
185-
returnfixer.removeRange(directive.range);
186-
},
187-
},
188-
],
189-
});
190-
}
191-
return{};
192-
},
193-
};
194-
195163
typeRulesConfig={
196164
[name: string]: {rule: Rule.RuleModule;severity: ErrorSeverity};
197165
};
@@ -201,12 +169,7 @@ export const allRules: RulesConfig = LintRules.reduce(
201169
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
202170
returnacc;
203171
},
204-
{
205-
'no-unused-directives': {
206-
rule: NoUnusedDirectivesRule,
207-
severity: ErrorSeverity.Error,
208-
},
209-
}asRulesConfig,
172+
{}asRulesConfig,
210173
);
211174

212175
exportconstrecommendedRules: RulesConfig=LintRules.filter(
@@ -216,12 +179,7 @@ export const recommendedRules: RulesConfig = LintRules.filter(
216179
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
217180
returnacc;
218181
},
219-
{
220-
'no-unused-directives': {
221-
rule: NoUnusedDirectivesRule,
222-
severity: ErrorSeverity.Error,
223-
},
224-
}asRulesConfig,
182+
{}asRulesConfig,
225183
);
226184

227185
exportfunctionmapErrorSeverityToESlint(

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); [eprh] Remove NoUnusedOptOutDirectives (#34703) · react/react@19f65ff · GitHub
Skip to content

Commit 19f65ff

Browse files
authored
[eprh] Remove NoUnusedOptOutDirectives (#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#31407 --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34703). * __->__ #34703 * #34700
1 parent 26b177b commit 19f65ff

5 files changed

Lines changed: 14 additions & 262 deletions

File tree

‎compiler/packages/eslint-plugin-react-compiler/__tests__/NoUnusedDirectivesRule-test.ts‎

Lines changed: 0 additions & 58 deletions
This file was deleted.

‎compiler/packages/eslint-plugin-react-compiler/src/rules/ReactCompilerRule.ts‎

Lines changed: 8 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -161,69 +161,21 @@ function makeRule(rule: LintRule): Rule.RuleModule {
161161
};
162162
}
163163

164-
exportconstNoUnusedDirectivesRule: Rule.RuleModule={
165-
meta: {
166-
type: 'suggestion',
167-
docs: {
168-
recommended: true,
169-
},
170-
fixable: 'code',
171-
hasSuggestions: true,
172-
// validation is done at runtime with zod
173-
schema: [{type: 'object',additionalProperties: true}],
174-
},
175-
create(context: Rule.RuleContext): Rule.RuleListener{
176-
constresults=getReactCompilerResult(context);
177-
178-
for(constdirectiveofresults.unusedOptOutDirectives){
179-
context.report({
180-
message: `Unused '${directive.directive}' directive`,
181-
loc: directive.loc,
182-
suggest: [
183-
{
184-
desc: 'Remove the directive',
185-
fix(fixer): Rule.Fix{
186-
returnfixer.removeRange(directive.range);
187-
},
188-
},
189-
],
190-
});
191-
}
192-
return{};
193-
},
194-
};
195-
196164
typeRulesConfig={
197165
[name: string]: {rule: Rule.RuleModule;severity: ErrorSeverity};
198166
};
199167

200-
exportconstallRules: RulesConfig=LintRules.reduce(
201-
(acc,rule)=>{
202-
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
203-
returnacc;
204-
},
205-
{
206-
'no-unused-directives': {
207-
rule: NoUnusedDirectivesRule,
208-
severity: ErrorSeverity.Error,
209-
},
210-
}asRulesConfig,
211-
);
168+
exportconstallRules: RulesConfig=LintRules.reduce((acc,rule)=>{
169+
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
170+
returnacc;
171+
},{}asRulesConfig);
212172

213173
exportconstrecommendedRules: RulesConfig=LintRules.filter(
214174
rule=>rule.recommended,
215-
).reduce(
216-
(acc,rule)=>{
217-
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
218-
returnacc;
219-
},
220-
{
221-
'no-unused-directives': {
222-
rule: NoUnusedDirectivesRule,
223-
severity: ErrorSeverity.Error,
224-
},
225-
}asRulesConfig,
226-
);
175+
).reduce((acc,rule)=>{
176+
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
177+
returnacc;
178+
},{}asRulesConfig);
227179

228180
exportfunctionmapErrorSeverityToESlint(
229181
severity: ErrorSeverity,

‎compiler/packages/eslint-plugin-react-compiler/src/shared/RunReactCompiler.ts‎

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import{transformFromAstSync,traverse}from'@babel/core';
8+
import{transformFromAstSync}from'@babel/core';
99
import{parseasbabelParse}from'@babel/parser';
10-
import{Directive,File}from'@babel/types';
10+
import{File}from'@babel/types';
1111
// @ts-expect-error: no types available
1212
importPluginProposalPrivateMethodsfrom'@babel/plugin-proposal-private-methods';
1313
importBabelPluginReactCompiler,{
1414
parsePluginOptions,
1515
validateEnvironmentConfig,
16-
OPT_OUT_DIRECTIVES,
1716
typePluginOptions,
1817
}from'babel-plugin-react-compiler/src';
1918
import{Logger,LoggerEvent}from'babel-plugin-react-compiler/src/Entrypoint';
2019
importtype{SourceCode}from'eslint';
21-
import{SourceLocation}from'estree';
2220
// @ts-expect-error: no types available
2321
import*asHermesParserfrom'hermes-parser';
2422
import{isDeepStrictEqual}from'util';
@@ -45,17 +43,11 @@ const COMPILER_OPTIONS: PluginOptions = {
4543
}),
4644
};
4745

48-
exporttypeUnusedOptOutDirective={
49-
loc: SourceLocation;
50-
range: [number,number];
51-
directive: string;
52-
};
5346
exporttypeRunCacheEntry={
5447
sourceCode: string;
5548
filename: string;
5649
userOpts: PluginOptions;
5750
flowSuppressions: Array<{line: number;code: string}>;
58-
unusedOptOutDirectives: Array<UnusedOptOutDirective>;
5951
events: Array<LoggerEvent>;
6052
};
6153

@@ -87,25 +79,6 @@ function getFlowSuppressions(
8779
returnresults;
8880
}
8981

90-
functionfilterUnusedOptOutDirectives(
91-
directives: ReadonlyArray<Directive>,
92-
): Array<UnusedOptOutDirective>{
93-
constresults: Array<UnusedOptOutDirective>=[];
94-
for(constdirectiveofdirectives){
95-
if(
96-
OPT_OUT_DIRECTIVES.has(directive.value.value)&&
97-
directive.loc!=null
98-
){
99-
results.push({
100-
loc: directive.loc,
101-
directive: directive.value.value,
102-
range: [directive.start!,directive.end!],
103-
});
104-
}
105-
}
106-
returnresults;
107-
}
108-
10982
functionrunReactCompilerImpl({
11083
sourceCode,
11184
filename,
@@ -125,7 +98,6 @@ function runReactCompilerImpl({
12598
filename,
12699
userOpts,
127100
flowSuppressions: [],
128-
unusedOptOutDirectives: [],
129101
events: [],
130102
};
131103
constuserLogger: Logger|null=options.logger;
@@ -181,29 +153,6 @@ function runReactCompilerImpl({
181153
configFile: false,
182154
babelrc: false,
183155
});
184-
185-
if(results.events.filter(e=>e.kind==='CompileError').length===0){
186-
traverse(babelAST,{
187-
FunctionDeclaration(path){
188-
path.node;
189-
results.unusedOptOutDirectives.push(
190-
...filterUnusedOptOutDirectives(path.node.body.directives),
191-
);
192-
},
193-
ArrowFunctionExpression(path){
194-
if(path.node.body.type==='BlockStatement'){
195-
results.unusedOptOutDirectives.push(
196-
...filterUnusedOptOutDirectives(path.node.body.directives),
197-
);
198-
}
199-
},
200-
FunctionExpression(path){
201-
results.unusedOptOutDirectives.push(
202-
...filterUnusedOptOutDirectives(path.node.body.directives),
203-
);
204-
},
205-
});
206-
}
207156
}catch(err){
208157
/* errors handled by injected logger */
209158
}

‎packages/eslint-plugin-react-hooks/src/shared/ReactCompiler.ts‎

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -160,38 +160,6 @@ function makeRule(rule: LintRule): Rule.RuleModule {
160160
};
161161
}
162162

163-
exportconstNoUnusedDirectivesRule: Rule.RuleModule={
164-
meta: {
165-
type: 'suggestion',
166-
docs: {
167-
recommended: true,
168-
},
169-
fixable: 'code',
170-
hasSuggestions: true,
171-
// validation is done at runtime with zod
172-
schema: [{type: 'object',additionalProperties: true}],
173-
},
174-
create(context: Rule.RuleContext): Rule.RuleListener{
175-
constresults=getReactCompilerResult(context);
176-
177-
for(constdirectiveofresults.unusedOptOutDirectives){
178-
context.report({
179-
message: `Unused '${directive.directive}' directive`,
180-
loc: directive.loc,
181-
suggest: [
182-
{
183-
desc: 'Remove the directive',
184-
fix(fixer): Rule.Fix{
185-
returnfixer.removeRange(directive.range);
186-
},
187-
},
188-
],
189-
});
190-
}
191-
return{};
192-
},
193-
};
194-
195163
typeRulesConfig={
196164
[name: string]: {rule: Rule.RuleModule;severity: ErrorSeverity};
197165
};
@@ -201,12 +169,7 @@ export const allRules: RulesConfig = LintRules.reduce(
201169
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
202170
returnacc;
203171
},
204-
{
205-
'no-unused-directives': {
206-
rule: NoUnusedDirectivesRule,
207-
severity: ErrorSeverity.Error,
208-
},
209-
}asRulesConfig,
172+
{}asRulesConfig,
210173
);
211174

212175
exportconstrecommendedRules: RulesConfig=LintRules.filter(
@@ -216,12 +179,7 @@ export const recommendedRules: RulesConfig = LintRules.filter(
216179
acc[rule.name]={rule: makeRule(rule),severity: rule.severity};
217180
returnacc;
218181
},
219-
{
220-
'no-unused-directives': {
221-
rule: NoUnusedDirectivesRule,
222-
severity: ErrorSeverity.Error,
223-
},
224-
}asRulesConfig,
182+
{}asRulesConfig,
225183
);
226184

227185
exportfunctionmapErrorSeverityToESlint(

0 commit comments

Comments
 (0)