mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[eslint-plugin] Enable validation passes
This commit is contained in:
@@ -13,6 +13,7 @@ export {
|
||||
} from "./CompilerError";
|
||||
export {
|
||||
CompilerPipelineValue,
|
||||
PluginOptions,
|
||||
compileFn as compile,
|
||||
compileProgram,
|
||||
parsePluginOptions,
|
||||
|
||||
+20
@@ -41,6 +41,26 @@ const tests: ForgetTestCases = {
|
||||
},
|
||||
],
|
||||
invalid: [
|
||||
{
|
||||
name: "[InvalidInput] Ref access during render",
|
||||
code: normalizeIndent`
|
||||
function Component(props) {
|
||||
const ref = useRef(null);
|
||||
const value = ref.current;
|
||||
return value;
|
||||
}
|
||||
`,
|
||||
errors: [
|
||||
{
|
||||
message:
|
||||
"[ReactForget] InvalidInput: Ref values (the `current` property) may not be accessed during render. Cannot access ref value at freeze $23:TObject<BuiltInRefValue> (5:5)",
|
||||
line: 5,
|
||||
column: 10,
|
||||
endColumn: 15,
|
||||
endLine: 5,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "[Invariant] Defined after use",
|
||||
code: normalizeIndent`
|
||||
|
||||
+10
-1
@@ -9,6 +9,7 @@ import * as parser from "@babel/parser";
|
||||
import traverse from "@babel/traverse";
|
||||
import {
|
||||
CompilerError,
|
||||
PluginOptions,
|
||||
compileProgram,
|
||||
parsePluginOptions,
|
||||
} from "babel-plugin-react-forget";
|
||||
@@ -33,8 +34,16 @@ const rule: Rule.RuleModule = {
|
||||
traverse(babelAST, {
|
||||
Program(prog) {
|
||||
try {
|
||||
const opts: Partial<PluginOptions> = {
|
||||
panicOnBailout: false,
|
||||
environment: {
|
||||
validateHooksUsage: true,
|
||||
validateFrozenLambdas: true,
|
||||
validateRefAccessDuringRender: true,
|
||||
},
|
||||
};
|
||||
compileProgram(prog, {
|
||||
opts: parsePluginOptions({ panicOnBailout: false }),
|
||||
opts: parsePluginOptions(opts),
|
||||
filename: context.filename,
|
||||
comments: babelAST.comments ?? [],
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user