[eslint-plugin] Add test for invariants
Turning off this flag makes only critical errors throw, so TODO errors will no longer be surfaced by the plugin. The previously failing test for unsupported syntax is now valid.
Lauren Tan committed
Jun 15, 2023 at 14:57 UTC
0fdb1e5ac74e46ad4302c31a4334f7dd8dc8765f
2 files changed
+25
-4
compiler/forget/packages/eslint-plugin-react-forget/__tests__/ReactForgetDiagnostics-test.ts
+24
-3
@@ -30,8 +30,6 @@ const tests: ForgetTestCases = {
30
}
31
`,
32
},
33
- ],
34
- invalid: [
33
{
34
name: "Unsupported syntax",
35
code: normalizeIndent`
@@ -40,8 +38,31 @@ const tests: ForgetTestCases = {
38
return y * x;
39
}
40
`,
41
+ },
42
+ ],
43
+ invalid: [
44
+ {
45
+ name: "[Invariant] Defined after use",
46
+ code: normalizeIndent`
47
+ function Component(props) {
48
+ let y = function () {
49
+ m(x);
50
+ };
51
+
52
+ let x = { a };
53
+ m(x);
54
+ return y;
55
+ }
56
+ `,
57
errors: [
44
- "[ReactForget] Todo: (BuildHIR::lowerStatement) Handle var kinds in VariableDeclaration (3:3)",
58
+ {
59
+ message:
60
+ "[ReactForget] Invariant: EnterSSA: Expected identifier to be defined before being used. Identifier x$2 is undefined (7:7)",
61
+ line: 7,
62
+ column: 3,
63
+ endColumn: 17,
64
+ endLine: 7,
65
+ },
66
],
67
},
68
],
compiler/forget/packages/eslint-plugin-react-forget/src/rules/ReactForgetDiagnostics.ts
+1
-1
@@ -34,7 +34,7 @@ const rule: Rule.RuleModule = {
34
Program(prog) {
35
try {
36
compileProgram(prog, {
37
- opts: parsePluginOptions(null), // use defaults for now
37
+ opts: parsePluginOptions({ panicOnBailout: false }),
38
filename: context.filename,
39
comments: babelAST.comments ?? [],
40
});