@samitouri / QOS-React-2 / commits / 0d01d5f69c

[eslint-plugin] Enable validation passes

Lauren Tan committed Jun 15, 2023 at 14:57 UTC 0d01d5f69cd7ded5513a86b72a9d719f837945fd
3 files changed +31 -1
compiler/forget/packages/babel-plugin-react-forget/src/index.ts
+1
@@ -13,6 +13,7 @@ export {
13 } from "./CompilerError";
14 export {
15 CompilerPipelineValue,
16 + PluginOptions,
17 compileFn as compile,
18 compileProgram,
19 parsePluginOptions,
compiler/forget/packages/eslint-plugin-react-forget/__tests__/ReactForgetDiagnostics-test.ts
+20
@@ -41,6 +41,26 @@ const tests: ForgetTestCases = {
41 },
42 ],
43 invalid: [
44 + {
45 + name: "[InvalidInput] Ref access during render",
46 + code: normalizeIndent`
47 + function Component(props) {
48 + const ref = useRef(null);
49 + const value = ref.current;
50 + return value;
51 + }
52 + `,
53 + errors: [
54 + {
55 + message:
56 + "[ReactForget] InvalidInput: Ref values (the `current` property) may not be accessed during render. Cannot access ref value at freeze $23:TObject<BuiltInRefValue> (5:5)",
57 + line: 5,
58 + column: 10,
59 + endColumn: 15,
60 + endLine: 5,
61 + },
62 + ],
63 + },
64 {
65 name: "[Invariant] Defined after use",
66 code: normalizeIndent`
compiler/forget/packages/eslint-plugin-react-forget/src/rules/ReactForgetDiagnostics.ts
+10 -1
@@ -9,6 +9,7 @@ import * as parser from "@babel/parser";
9 import traverse from "@babel/traverse";
10 import {
11 CompilerError,
12 + PluginOptions,
13 compileProgram,
14 parsePluginOptions,
15 } from "babel-plugin-react-forget";
@@ -33,8 +34,16 @@ const rule: Rule.RuleModule = {
34 traverse(babelAST, {
35 Program(prog) {
36 try {
37 + const opts: Partial<PluginOptions> = {
38 + panicOnBailout: false,
39 + environment: {
40 + validateHooksUsage: true,
41 + validateFrozenLambdas: true,
42 + validateRefAccessDuringRender: true,
43 + },
44 + };
45 compileProgram(prog, {
37 - opts: parsePluginOptions({ panicOnBailout: false }),
46 + opts: parsePluginOptions(opts),
47 filename: context.filename,
48 comments: babelAST.comments ?? [],
49 });