From 059365d7260d5d7ba2a722aa5b427ab2d3b50877 Mon Sep 17 00:00:00 2001 From: Lauren Tan Date: Tue, 20 Jun 2023 12:30:05 -0400 Subject: [PATCH] [eslint-plugin] Temporarily only lint on 'use forget' Temporarily enabling 'use forget' only mode for the linter to address #1751 so we can land the stack internally --- .../__tests__/ReactForgetDiagnostics-test.ts | 16 ++++++++++------ .../src/rules/ReactForgetDiagnostics.ts | 1 + 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/compiler/forget/packages/eslint-plugin-react-forget/__tests__/ReactForgetDiagnostics-test.ts b/compiler/forget/packages/eslint-plugin-react-forget/__tests__/ReactForgetDiagnostics-test.ts index e00821991c..4a8d1d4afb 100644 --- a/compiler/forget/packages/eslint-plugin-react-forget/__tests__/ReactForgetDiagnostics-test.ts +++ b/compiler/forget/packages/eslint-plugin-react-forget/__tests__/ReactForgetDiagnostics-test.ts @@ -23,6 +23,7 @@ const tests: ForgetTestCases = { name: "Basic example", code: normalizeIndent` function foo(x, y) { + 'use forget'; if (x) { return foo(false, y); } @@ -34,6 +35,7 @@ const tests: ForgetTestCases = { name: "Unsupported syntax", code: normalizeIndent` function foo(x) { + 'use forget'; var y = 1; return y * x; } @@ -45,6 +47,7 @@ const tests: ForgetTestCases = { name: "[InvalidInput] Ref access during render", code: normalizeIndent` function Component(props) { + 'use forget'; const ref = useRef(null); const value = ref.current; return value; @@ -53,11 +56,11 @@ const tests: ForgetTestCases = { errors: [ { message: - "[ReactForget] InvalidInput: Ref values (the `current` property) may not be accessed during render. Cannot access ref value at freeze $23:TObject (5:5)", - line: 5, + "[ReactForget] InvalidInput: Ref values (the `current` property) may not be accessed during render. Cannot access ref value at freeze $23:TObject (6:6)", + line: 6, column: 10, endColumn: 15, - endLine: 5, + endLine: 6, }, ], }, @@ -65,6 +68,7 @@ const tests: ForgetTestCases = { name: "[Invariant] Defined after use", code: normalizeIndent` function Component(props) { + 'use forget'; let y = function () { m(x); }; @@ -77,11 +81,11 @@ const tests: ForgetTestCases = { errors: [ { message: - "[ReactForget] Invariant: EnterSSA: Expected identifier to be defined before being used. Identifier x$2 is undefined (7:7)", - line: 7, + "[ReactForget] Invariant: EnterSSA: Expected identifier to be defined before being used. Identifier x$2 is undefined (8:8)", + line: 8, column: 3, endColumn: 17, - endLine: 7, + endLine: 8, }, ], }, diff --git a/compiler/forget/packages/eslint-plugin-react-forget/src/rules/ReactForgetDiagnostics.ts b/compiler/forget/packages/eslint-plugin-react-forget/src/rules/ReactForgetDiagnostics.ts index b879dceaa5..886b0c6d37 100644 --- a/compiler/forget/packages/eslint-plugin-react-forget/src/rules/ReactForgetDiagnostics.ts +++ b/compiler/forget/packages/eslint-plugin-react-forget/src/rules/ReactForgetDiagnostics.ts @@ -27,6 +27,7 @@ const rule: Rule.RuleModule = { const filename = context.filename ?? context.getFilename(); const opts: Partial = { + enableOnlyOnUseForgetDirective: true, panicOnBailout: false, environment: { validateHooksUsage: true,