@samitouri / QOS-React / commits / 48024b76bb

Fix lints

Mike Vitousek committed Feb 9, 2024 at 14:50 UTC 48024b76bbb29028ea94f816efb5b69eeb01e948
4 files changed +25 -22
compiler/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts
+5 -3
@@ -199,7 +199,7 @@ export function compileProgram(
199 const suppressions = findProgramSuppressions(
200 pass.comments,
201 options.eslintSuppressionRules ?? DEFAULT_ESLINT_SUPPRESSIONS,
202 - options.flowSuppressions,
202 + options.flowSuppressions
203 );
204 const lintError = suppressionsToCompilerError(suppressions);
205 let hasCriticalError = lintError != null;
@@ -224,8 +224,10 @@ export function compileProgram(
224 * Program node itself. We need to figure out whether an eslint suppression range
225 * applies to this function first.
226 */
227 - const suppressionsInFunction =
228 - filterSuppressionsThatAffectFunction(suppressions, fn);
227 + const suppressionsInFunction = filterSuppressionsThatAffectFunction(
228 + suppressions,
229 + fn
230 + );
231 if (suppressionsInFunction.length > 0) {
232 handleError(lintError, pass, fn.node.loc ?? null);
233 }
compiler/packages/babel-plugin-react-forget/src/Entrypoint/Suppression.ts
+13 -12
@@ -28,8 +28,7 @@ export type SuppressionRange = {
28 source: SuppressionSource;
29 };
30
31 -type SuppressionSource =
32 - 'Eslint' | 'Flow'
31 +type SuppressionSource = "Eslint" | "Flow";
32
33 /**
34 * An suppression affects a function if:
@@ -78,7 +77,7 @@ export function filterSuppressionsThatAffectFunction(
77 export function findProgramSuppressions(
78 programComments: Array<t.Comment>,
79 ruleNames: Array<string>,
81 - flowSuppressions: boolean,
80 + flowSuppressions: boolean
81 ): Array<SuppressionRange> {
82 const suppressionRanges: Array<SuppressionRange> = [];
83 let disableComment: t.Comment | null = null;
@@ -92,7 +91,7 @@ export function findProgramSuppressions(
91 const disablePattern = new RegExp(`eslint-disable ${rulePattern}`);
92 const enablePattern = new RegExp(`eslint-enable ${rulePattern}`);
93 const flowSuppressionPattern = new RegExp(
95 - '\\$(FlowFixMe\\w*|FlowExpectedError|FlowIssue)\\[react\\-rule'
94 + "\\$(FlowFixMe\\w*|FlowExpectedError|FlowIssue)\\[react\\-rule"
95 );
96
97 for (const comment of programComments) {
@@ -110,7 +109,7 @@ export function findProgramSuppressions(
109 ) {
110 disableComment = comment;
111 enableComment = comment;
113 - source = 'Eslint';
112 + source = "Eslint";
113 }
114
115 if (
@@ -120,15 +119,15 @@ export function findProgramSuppressions(
119 ) {
120 disableComment = comment;
121 enableComment = comment;
123 - source = 'Flow';
122 + source = "Flow";
123 }
124
125 if (disablePattern.test(comment.value)) {
126 disableComment = comment;
128 - source = 'Eslint';
127 + source = "Eslint";
128 }
129
131 - if (enablePattern.test(comment.value) && source === 'Eslint') {
130 + if (enablePattern.test(comment.value) && source === "Eslint") {
131 enableComment = comment;
132 }
133
@@ -162,12 +161,14 @@ export function suppressionsToCompilerError(
161 }
162 let reason, suggestion;
163 switch (suppressionRange.source) {
165 - case 'Eslint':
166 - reason = "React Forget has bailed out of optimizing this component as one or more React eslint rules were disabled";
164 + case "Eslint":
165 + reason =
166 + "React Forget has bailed out of optimizing this component as one or more React eslint rules were disabled";
167 suggestion = "Remove the eslint disable";
168 break;
169 - case 'Flow':
170 - reason = "React Forget has bailed out of optimizing this component as one or more React rule violations were reported by Flow";
169 + case "Flow":
170 + reason =
171 + "React Forget has bailed out of optimizing this component as one or more React rule violations were reported by Flow";
172 suggestion = "Remove the Flow suppression and address the React error";
173 }
174 error.pushErrorDetail(
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.bailout-on-flow-suppression.js
+3 -3
@@ -1,7 +1,7 @@
1 // @enableFlowSuppressions
2
3 function Foo(props) {
4 - // $FlowFixMe[react-rule-hook]
5 - useX();
6 - return null;
4 + // $FlowFixMe[react-rule-hook]
5 + useX();
6 + return null;
7 }
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/no-flow-bailout-unrelated.js
+4 -4
@@ -1,8 +1,8 @@
1 // @enableFlowSuppressions
2
3 function Foo(props) {
4 - // $FlowFixMe[incompatible-type]
5 - useX();
6 - const x = new Foo(...props.foo, null, ...[props.bar]);
7 - return x;
4 + // $FlowFixMe[incompatible-type]
5 + useX();
6 + const x = new Foo(...props.foo, null, ...[props.bar]);
7 + return x;
8 }