From 48024b76bbb29028ea94f816efb5b69eeb01e948 Mon Sep 17 00:00:00 2001 From: Mike Vitousek Date: Fri, 9 Feb 2024 14:50:06 -0800 Subject: [PATCH] Fix lints --- .../src/Entrypoint/Program.ts | 8 +++--- .../src/Entrypoint/Suppression.ts | 25 ++++++++++--------- .../error.bailout-on-flow-suppression.js | 6 ++--- .../compiler/no-flow-bailout-unrelated.js | 8 +++--- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts b/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts index 6201af4d0d..04fa34234a 100644 --- a/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts +++ b/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts @@ -199,7 +199,7 @@ export function compileProgram( const suppressions = findProgramSuppressions( pass.comments, options.eslintSuppressionRules ?? DEFAULT_ESLINT_SUPPRESSIONS, - options.flowSuppressions, + options.flowSuppressions ); const lintError = suppressionsToCompilerError(suppressions); let hasCriticalError = lintError != null; @@ -224,8 +224,10 @@ export function compileProgram( * Program node itself. We need to figure out whether an eslint suppression range * applies to this function first. */ - const suppressionsInFunction = - filterSuppressionsThatAffectFunction(suppressions, fn); + const suppressionsInFunction = filterSuppressionsThatAffectFunction( + suppressions, + fn + ); if (suppressionsInFunction.length > 0) { handleError(lintError, pass, fn.node.loc ?? null); } diff --git a/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Suppression.ts b/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Suppression.ts index 84064cb213..78e2020b37 100644 --- a/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Suppression.ts +++ b/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Suppression.ts @@ -28,8 +28,7 @@ export type SuppressionRange = { source: SuppressionSource; }; -type SuppressionSource = - 'Eslint' | 'Flow' +type SuppressionSource = "Eslint" | "Flow"; /** * An suppression affects a function if: @@ -78,7 +77,7 @@ export function filterSuppressionsThatAffectFunction( export function findProgramSuppressions( programComments: Array, ruleNames: Array, - flowSuppressions: boolean, + flowSuppressions: boolean ): Array { const suppressionRanges: Array = []; let disableComment: t.Comment | null = null; @@ -92,7 +91,7 @@ export function findProgramSuppressions( const disablePattern = new RegExp(`eslint-disable ${rulePattern}`); const enablePattern = new RegExp(`eslint-enable ${rulePattern}`); const flowSuppressionPattern = new RegExp( - '\\$(FlowFixMe\\w*|FlowExpectedError|FlowIssue)\\[react\\-rule' + "\\$(FlowFixMe\\w*|FlowExpectedError|FlowIssue)\\[react\\-rule" ); for (const comment of programComments) { @@ -110,7 +109,7 @@ export function findProgramSuppressions( ) { disableComment = comment; enableComment = comment; - source = 'Eslint'; + source = "Eslint"; } if ( @@ -120,15 +119,15 @@ export function findProgramSuppressions( ) { disableComment = comment; enableComment = comment; - source = 'Flow'; + source = "Flow"; } if (disablePattern.test(comment.value)) { disableComment = comment; - source = 'Eslint'; + source = "Eslint"; } - if (enablePattern.test(comment.value) && source === 'Eslint') { + if (enablePattern.test(comment.value) && source === "Eslint") { enableComment = comment; } @@ -162,12 +161,14 @@ export function suppressionsToCompilerError( } let reason, suggestion; switch (suppressionRange.source) { - case 'Eslint': - reason = "React Forget has bailed out of optimizing this component as one or more React eslint rules were disabled"; + case "Eslint": + reason = + "React Forget has bailed out of optimizing this component as one or more React eslint rules were disabled"; suggestion = "Remove the eslint disable"; break; - case 'Flow': - reason = "React Forget has bailed out of optimizing this component as one or more React rule violations were reported by Flow"; + case "Flow": + reason = + "React Forget has bailed out of optimizing this component as one or more React rule violations were reported by Flow"; suggestion = "Remove the Flow suppression and address the React error"; } error.pushErrorDetail( diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.bailout-on-flow-suppression.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.bailout-on-flow-suppression.js index 9a3e99daab..957004260e 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.bailout-on-flow-suppression.js +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.bailout-on-flow-suppression.js @@ -1,7 +1,7 @@ // @enableFlowSuppressions function Foo(props) { - // $FlowFixMe[react-rule-hook] - useX(); - return null; + // $FlowFixMe[react-rule-hook] + useX(); + return null; } diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/no-flow-bailout-unrelated.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/no-flow-bailout-unrelated.js index f99299f45e..c5c3fd5295 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/no-flow-bailout-unrelated.js +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/no-flow-bailout-unrelated.js @@ -1,8 +1,8 @@ // @enableFlowSuppressions function Foo(props) { - // $FlowFixMe[incompatible-type] - useX(); - const x = new Foo(...props.foo, null, ...[props.bar]); - return x; + // $FlowFixMe[incompatible-type] + useX(); + const x = new Foo(...props.foo, null, ...[props.bar]); + return x; }