[eprh] Temporarily disable ref access in render validation (#32839)

This rule currently has a few false positives, so let's disable it for
now (just in the eslint rule, it's still enabled in the compiler) while
we iterate on it.
This commit is contained in:
lauren 2025-04-09 14:49:31 -04:00 committed by GitHub
parent 096dd7385d
commit ff697fc58b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 20 additions and 62 deletions

View File

@ -92,36 +92,8 @@ const tests: CompilerTestCases = {
}
`,
},
{
// Don't report the issue if Flow already has
name: '[InvalidInput] Ref access during render',
code: normalizeIndent`
function Component(props) {
const ref = useRef(null);
// $FlowFixMe[react-rule-unsafe-ref]
const value = ref.current;
return value;
}
`,
},
],
invalid: [
{
name: '[InvalidInput] Ref access during render',
code: normalizeIndent`
function Component(props) {
const ref = useRef(null);
const value = ref.current;
return value;
}
`,
errors: [
{
message:
'Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)',
},
],
},
{
name: 'Reportable levels can be configured',
options: [{reportableLevels: new Set([ErrorSeverity.Todo])}],

View File

@ -105,6 +105,9 @@ const COMPILER_OPTIONS: Partial<PluginOptions> = {
panicThreshold: 'none',
// Don't emit errors on Flow suppressions--Flow already gave a signal
flowSuppressions: false,
environment: validateEnvironmentConfig({
validateRefAccessDuringRender: false,
}),
};
const rule: Rule.RuleModule = {
@ -149,10 +152,14 @@ const rule: Rule.RuleModule = {
}
let shouldReportUnusedOptOutDirective = true;
const options: PluginOptions = {
...parsePluginOptions(userOpts),
const options: PluginOptions = parsePluginOptions({
...COMPILER_OPTIONS,
};
...userOpts,
environment: {
...COMPILER_OPTIONS.environment,
...userOpts.environment,
},
});
const userLogger: Logger | null = options.logger;
options.logger = {
logEvent: (filename, event): void => {

View File

@ -94,36 +94,8 @@ const tests: CompilerTestCases = {
}
`,
},
{
// Don't report the issue if Flow already has
name: '[InvalidInput] Ref access during render',
code: normalizeIndent`
function Component(props) {
const ref = useRef(null);
// $FlowFixMe[react-rule-unsafe-ref]
const value = ref.current;
return value;
}
`,
},
],
invalid: [
{
name: '[InvalidInput] Ref access during render',
code: normalizeIndent`
function Component(props) {
const ref = useRef(null);
const value = ref.current;
return value;
}
`,
errors: [
{
message:
'Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)',
},
],
},
{
name: 'Reportable levels can be configured',
options: [{reportableLevels: new Set([ErrorSeverity.Todo])}],

View File

@ -107,6 +107,9 @@ const COMPILER_OPTIONS: Partial<PluginOptions> = {
panicThreshold: 'none',
// Don't emit errors on Flow suppressions--Flow already gave a signal
flowSuppressions: false,
environment: validateEnvironmentConfig({
validateRefAccessDuringRender: false,
}),
};
const rule: Rule.RuleModule = {
@ -151,10 +154,14 @@ const rule: Rule.RuleModule = {
}
let shouldReportUnusedOptOutDirective = true;
const options: PluginOptions = {
...parsePluginOptions(userOpts),
const options: PluginOptions = parsePluginOptions({
...COMPILER_OPTIONS,
};
...userOpts,
environment: {
...COMPILER_OPTIONS.environment,
...userOpts.environment,
},
});
const userLogger: Logger | null = options.logger;
options.logger = {
logEvent: (eventFilename, event): void => {