mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Fix lints
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<t.Comment>,
|
||||
ruleNames: Array<string>,
|
||||
flowSuppressions: boolean,
|
||||
flowSuppressions: boolean
|
||||
): Array<SuppressionRange> {
|
||||
const suppressionRanges: Array<SuppressionRange> = [];
|
||||
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(
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
// @enableFlowSuppressions
|
||||
|
||||
function Foo(props) {
|
||||
// $FlowFixMe[react-rule-hook]
|
||||
useX();
|
||||
return null;
|
||||
// $FlowFixMe[react-rule-hook]
|
||||
useX();
|
||||
return null;
|
||||
}
|
||||
|
||||
+4
-4
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user