Skip to content
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

feat(react): remove PropTypes from all react components #1245

Merged
merged 6 commits into from
Dec 5, 2023

Conversation

scurker
Copy link
Member

@scurker scurker commented Oct 17, 2023

BREAKING CHANGE: This removes all PropTypes from react components. If an author needs to depend on specific types, the recommendation going forward is to use Typescript types to validate React component props.

closes #1164

@scurker scurker requested a review from a team October 17, 2023 21:31
@github-actions
Copy link
Contributor

Preview branch generated at https://remove-prop-types.d1gko6en628vir.amplifyapp.com

@scurker
Copy link
Member Author

scurker commented Oct 17, 2023

99% of the output here was done via the following codemod and jscodeshift commands:

Codemod

import type {
  API,
  FileInfo
} from 'jscodeshift'

export default function (file: FileInfo, api: API) {
  const j = api.jscodeshift;
  const root = j(file.source);

  // Find assignment propTypes and remove them
  const assignmentPropTypes = root
    .find(j.AssignmentExpression, {
      left: {
        property: {
          name: 'propTypes'
        }
      }
    })
  assignmentPropTypes.remove();

  // Find static propTypes from class based components and remove them
  const staticPropTypes = root
    .find(j.ClassProperty, {
      key: {
        type: 'Identifier',
        name: 'propTypes'
      },
      static: true
    })
  staticPropTypes.remove()

  // Remove import declaration
  const importPropType = root
    .find(j.ImportDeclaration, {
      source: {
        value: 'prop-types'
      }
    })
  importPropType.remove()

  return root.toSource();
}

CLI Command

npx jscodeshift -t ./remove-react-prop-types.ts --parser=tsx --extensions=tsx ./packages/react/src/**/*.tsx

@scurker scurker marked this pull request as ready for review October 17, 2023 22:18
@scurker scurker requested a review from a team as a code owner October 17, 2023 22:18
Copy link
Collaborator

@thuey thuey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a lot of places where className was added, but it seems unnecessary, unless I'm missing something.

@scurker scurker merged commit 301c546 into develop Dec 5, 2023
5 checks passed
@scurker scurker deleted the remove-prop-types branch December 5, 2023 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove PropTypes from React Components
2 participants