brandongregoryscott / eslint-plugin-collation

ESLint plugin for making your code easier to read, with autofix and TypeScript support
https://eslint-plugin-collation.brandonscott.me
Apache License 2.0
4 stars 0 forks source link

Rule: `no-prop-destructure` #33

Open brandongregoryscott opened 2 years ago

brandongregoryscott commented 2 years ago

Implement a rule that converts destructured props in a function component into the body of the function, i.e.

interface ButtonProps {
  appearance?: string;
  backgroundColor?: string;
  borderRadius?: string | number;
  onClick: () => void;
}

const Button: React.FC<ButtonProps> = ({
  appearance,
  backgroundColor,
  borderRadius,
  onClick,
}) => {
  return <button></button>;
};

will be transformed to:

interface ButtonProps {
  appearance?: string;
  backgroundColor?: string;
  borderRadius?: string | number;
  onClick: () => void;
}

const Button: React.FC<ButtonProps> = (props) => {
  const { appearance, backgroundColor, borderRadius, onClick } = props;
  return <button></button>;
};
brandongregoryscott commented 2 years ago

Can reference react/destructuring-assignment for implementation ideas, but it does not have auto-fix support