Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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])}],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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])}],
Expand Down
13 changes: 10 additions & 3 deletions packages/eslint-plugin-react-hooks/src/rules/ReactCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 => {
Expand Down
Loading