jsx-eslint/eslint-plugin-react

[Bug]: autofix for `sort-prop-types` breaks code containing comments

Open

#3794 opened on Aug 5, 2024

View on GitHub
 (0 comments) (0 reactions) (0 assignees)JavaScript (8,630 stars) (2,797 forks)batch import
bughelp wanted

Description

Is there an existing issue for this?

  • I have searched the existing issues and my issue is unique
  • My issue appears in the command-line and not only in the text editor

Description Overview

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;
};

Component

function ContractVersionWizard(props: Props) {
  return <div />;
}

Relevant rule config:

    "react/sort-prop-types": [
      "error",
      {
        "callbacksLast": true,
        "requiredFirst": true,
        "sortShapeProp": true,
        "noSortAlphabetically": true,
        "checkTypes": true
      }
    ]

As discussed in #3783

Expected Behavior

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;
};

### eslint-plugin-react version

v7.34.4

### eslint version

v8.57.0

### node version

v20.14.10

Contributor guide