jsx-eslint / eslint-plugin-react

React-specific linting rules for ESLint
MIT License
9k stars 2.77k forks source link

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

Open tylerlaprade opened 3 months ago

tylerlaprade commented 3 months ago

Is there an existing issue for this?

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