-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: sort-prop-types
's autofix doesn't move the semicolon, producing broken code, on single-line Props types
#3783
Comments
sort-prop-types
's autofix is missing a semicolon, producing broken codesort-prop-types
's autofix is missing a semicolon, producing broken code, on single-line Props types
sort-prop-types
's autofix is missing a semicolon, producing broken code, on single-line Props typessort-prop-types
's autofix doesn't move the semicolon, producing broken code, on single-line Props types
UPDATE: I found another case which produces an incorrect autofix, this one on a multi-line Props. It seems to be due to comments. Notice that the comments have been duplicated, three props have disappeared, and part of a typehint is on a line by itself. Starting code:type Props = {
onClose: () => void;
onSave?: () => void;
initialContractInfo?: ContractInfo; // used to pre-populate the form just for our tests
contractVersionTraceId?: TraceId; // used when editing an existing contract
contractContainerId: TraceId;
wizardStartIndex?: number;
contractStatus?: BackendContractStatus;
contractVersion?: BackendContractVersion;
}; Auto-fixed code:type Props = {
initialContractInfo?: ContractInfo; // used to pre-populate the form just for our tests
// used to pre-populate the form just for our tests
contractVersionTraceId?: TraceId; // used when editing an existing contract
// used when editing an existing contract
contractContainerId: TraceId;
dContractVersion;
onClose: () => void;
onSave?: () => void;
}; Expected result:type Props = {
initialContractInfo?: ContractInfo; // used to pre-populate the form just for our tests
contractVersionTraceId?: TraceId; // used when editing an existing contract
contractContainerId: TraceId;
wizardStartIndex?: number;
contractStatus?: BackendContractStatus;
contractVersion?: BackendContractVersion;
onClose: () => void;
onSave?: () => void;
}; |
@tylerlaprade can you provide the component code these are associated with? it won't repro without a component. |
Full codetype CustomProps = { onChange: (event: { target: { name: string; value: string } }) => void; name: string };
function PercentFormatCustom(props: CustomProps) {
return (
<div />
);
} type Props = {
onClose: () => void;
onSave?: () => void;
initialContractInfo?: ContractInfo; // used to pre-populate the form just for our tests
contractVersionTraceId?: TraceId; // used when editing an existing contract
contractContainerId: TraceId;
wizardStartIndex?: number;
contractStatus?: BackendContractStatus;
contractVersion?: BackendContractVersion;
};
function ContractVersionWizard(props: Props) {
return <div />;
} and the relevant rule config: "react/sort-prop-types": [
"error",
{
"callbacksLast": true,
"requiredFirst": true,
"sortShapeProp": true,
"noSortAlphabetically": true,
"checkTypes": true
}
] |
Thanks, that definitely reproduces. I'm not sure how to fix it, tbh, but i can certainly disable the autofix for types. |
The autofix has been quite helpful in other cases. I imagine this would just be an issue of including the semicolon and/or comment in the moved token. |
I feel the second one can be a seperate issue, for better tracking. |
Yeah it'd be very helpful to file a separate issue for that. Thanks! |
Is there an existing issue for this?
Description Overview
sort-prop-types
, withcheckTypes: true
, breaks the code when run on single-line Props with autofix due to the semicolon staying at the end instead of moving.The props were rearranged without the semicolon dividing them
eslint --fix
Expected Behavior
Semicolon be moved along with the moved prop when running autofix
should become
Instead, it is fixing to
eslint-plugin-react version
v7.34.4
eslint version
v8.57.0
node version
v20.14.10
The text was updated successfully, but these errors were encountered: