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: add codemod #3836

Merged

Conversation

sashuk
Copy link
Contributor

@sashuk sashuk commented Aug 30, 2023

FX-4260

Description

This pull request adds a codemod that replaces BASE-aligned spacing property values with new spacing constants.

jscodeshift has the following problem when running this codemod:

However, both issues are solved by running lint or prettier after the codemod run (this recommendation was added to the changeset)

How to test

  • Run tests – check out this branch locally and run yarn run jest packages/picasso-codemod/src/v38.1.0/__tests__
  • Run actual codemod in Staff Portal – check out https://github.com/toptal/staff-portal/pull/10942 branch locally, drop last commit, and run npx @toptal/picasso-codemod v38.1.0

Screenshots

Typical change from https://github.com/toptal/staff-portal/pull/10942/files

Screenshot 2023-09-01 at 12 37 38

Running in Staff Portal (https://github.com/toptal/staff-portal/pull/10942)

Screenshot 2023-09-01 at 09 18 53

Development checks

All development checks should be done and set checked to pass the
GitHub Bot: TODOLess action

PR commands

List of available commands:

  • @toptal-bot run package:alpha-release - Release alpha version
  • @toptal-anvil ping reviewers - Ping FX team for review
PR Review Guidelines

When to approve? ✅

You are OK with merging this PR and

  1. You have no extra requests.
  2. You have optional requests.
    1. Add nit: to your comment. (ex. nit: I'd rename this variable from makeCircle to getCircle)

When to request changes? ❌

You are not OK with merging this PR because

  1. Something is broken after the changes.
  2. Acceptance criteria is not reached.
  3. Code is dirty.

When to comment (neither ✅ nor ❌)

You want your comments to be addressed before merging this PR in cases like:

  1. There are leftovers like unnecessary logs, comments, etc.
  2. You have an opinionated comment regarding the code that requires a discussion.
  3. You have questions.

How to handle the comments?

  1. An owner of a comment is the only one who can resolve it.
  2. An owner of a comment must resolve it when it's addressed.
  3. A PR owner must reply with ✅ when a comment is addressed.

@sashuk sashuk self-assigned this Aug 30, 2023
@changeset-bot
Copy link

changeset-bot bot commented Aug 30, 2023

🦋 Changeset detected

Latest commit: 6ab5499

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@toptal/picasso-codemod Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@toptal-devbot toptal-devbot temporarily deployed to staging August 30, 2023 15:33 Inactive
@toptal-devbot toptal-devbot temporarily deployed to staging August 30, 2023 16:48 Inactive
@toptal-devbot toptal-devbot temporarily deployed to staging August 31, 2023 16:05 Inactive
@sashuk sashuk force-pushed the fx-4260-create-codemod-for-replacing-spacings branch 2 times, most recently from d415edb to 6a39358 Compare August 31, 2023 16:21
@toptal-devbot toptal-devbot temporarily deployed to staging August 31, 2023 16:34 Inactive
@toptal toptal deleted a comment from toptal-devbot Sep 1, 2023
@sashuk sashuk force-pushed the fx-4260-create-codemod-for-replacing-spacings branch from 091923e to 4223b16 Compare September 1, 2023 06:22
@toptal toptal deleted a comment from toptal-devbot Sep 1, 2023
@toptal-devbot toptal-devbot temporarily deployed to staging September 1, 2023 07:14 Inactive
@toptal toptal deleted a comment from toptal-devbot Sep 1, 2023
@sashuk sashuk changed the base branch from master to feature/base-spacing September 1, 2023 07:57
@sashuk sashuk force-pushed the fx-4260-create-codemod-for-replacing-spacings branch 3 times, most recently from 2611f0a to 3b3a1e9 Compare September 1, 2023 08:22
@toptal-devbot toptal-devbot temporarily deployed to staging September 1, 2023 08:35 Inactive
@sashuk sashuk force-pushed the fx-4260-create-codemod-for-replacing-spacings branch 3 times, most recently from 347b393 to d077014 Compare September 1, 2023 10:15
@toptal toptal deleted a comment from toptal-devbot Sep 1, 2023
@toptal-devbot toptal-devbot temporarily deployed to staging September 1, 2023 10:27 Inactive
@sashuk sashuk force-pushed the fx-4260-create-codemod-for-replacing-spacings branch from d077014 to 1e5ecf7 Compare September 1, 2023 11:21
@toptal-devbot toptal-devbot temporarily deployed to staging September 1, 2023 11:33 Inactive
@sashuk sashuk marked this pull request as ready for review September 1, 2023 11:36
@sashuk sashuk requested a review from a team September 1, 2023 11:36
@dmaklygin
Copy link
Contributor

I tried to run it inside a Picasso and this is an output:

No files selected, nothing to do. 
All done. 
Results: 
0 errors
0 unmodified
0 skipped
0 ok
Time elapsed: 0.002seconds 

I think, we also should cover spec, test and story files, because they are also part of the project.

@sashuk
Copy link
Contributor Author

sashuk commented Sep 4, 2023

@dmaklygin Great suggestion, please let me add it!

@augustobmoura
Copy link

@toptal-bot run package:alpha-release

Copy link

@augustobmoura augustobmoura left a comment

Choose a reason for hiding this comment

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

Seems to be working as expected, but we have a bullet on AC for marking the old props as deprecated.

Make number and SpacingEnums as deprecated

Maybe we should move this AC to https://toptal-core.atlassian.net/browse/FX-4315?

.changeset/good-houses-end.md Outdated Show resolved Hide resolved
@sashuk
Copy link
Contributor Author

sashuk commented Sep 5, 2023

@dmaklygin Just checked it in picasso, I think the issue was that you need to use the following command (otherwise picasso-codemod looks for monorepo)

npx @toptal/picasso-codemod v38.1.0 packages/picasso/src/**/*.ts*

The output is the following

All done. 
Results: 
1 errors
2011 unmodified
0 skipped
0 ok
Time elapsed: 3.879seconds 

And 1 error stands for custom case that needs to be addressed manually

Manual update required for Container.bottom in packages/picasso/src/Pagination/story/Ellipsis.example.tsx:79
 ERR packages/picasso/src/PageTopBarMenu/PageTopBarMenu.tsx Transformation error (Unable to find @toptal/picasso or Container declaration to insert new spacing import)
Error: Unable to find @toptal/picasso or Container declaration to insert new spacing import
    at insertSpacingImport (/Users/aleksandr/toptal/tmp/picasso/packages/picasso-codemod/src/v38.1.0/utils/insert-spacing-import.ts:28:11)
    at transform (/Users/aleksandr/toptal/tmp/picasso/packages/picasso-codemod/src/v38.1.0/spacing-values.ts:108:24)
Manual update required for Container.bottom in packages/picasso/src/Pagination/story/Variants.example.tsx:8

Then yarn start is run and Picasso Storybook launches

Screenshot 2023-09-05 at 12 41 12

However, one bug was caught and addressed, thanks for checking on picasso!

@toptal toptal deleted a comment from toptal-devbot Sep 5, 2023
@sashuk
Copy link
Contributor Author

sashuk commented Sep 5, 2023

@augustobmoura

Maybe we should move this AC to https://toptal-core.atlassian.net/browse/FX-4315?

It looks like it belongs to this ticket, I'll address it in a separate pull request, thanks!

@sashuk sashuk requested a review from a team September 5, 2023 11:14
@sashuk
Copy link
Contributor Author

sashuk commented Sep 5, 2023

@toptal-bot run package:alpha-release

@toptal-devbot
Copy link
Collaborator

Your alpha package is ready 🎉
yarn add @topkit/analytics-charts@48.0.1-alpha-fx-4260-create-codemod-for-replacing-spacings-6ab549912.94+6ab549912
yarn add @toptal/picasso@37.7.1-alpha-fx-4260-create-codemod-for-replacing-spacings-6ab549912.12+6ab549912
yarn add @toptal/picasso-charts@51.0.1-alpha-fx-4260-create-codemod-for-replacing-spacings-6ab549912.94+6ab549912
yarn add @toptal/picasso-codemod@5.5.3-alpha-fx-4260-create-codemod-for-replacing-spacings-6ab549912.105+6ab549912
yarn add @toptal/picasso-forms@60.1.1-alpha-fx-4260-create-codemod-for-replacing-spacings-6ab549912.12+6ab549912
yarn add @toptal/picasso-pictograms@1.1.2-alpha-fx-4260-create-codemod-for-replacing-spacings-6ab549912.180+6ab549912
yarn add @toptal/picasso-provider@3.1.4-alpha-fx-4260-create-codemod-for-replacing-spacings-6ab549912.30+6ab549912
yarn add @toptal/picasso-rich-text-editor@5.0.4-alpha-fx-4260-create-codemod-for-replacing-spacings-6ab549912.6+6ab549912
yarn add @toptal/picasso-shared@12.0.1-alpha-fx-4260-create-codemod-for-replacing-spacings-6ab549912.225+6ab549912

@toptal toptal deleted a comment from toptal-devbot Sep 5, 2023
@toptal-devbot toptal-devbot temporarily deployed to staging September 5, 2023 11:25 Inactive
@sashuk
Copy link
Contributor Author

sashuk commented Sep 5, 2023

Latest package Staff Portal run result ✅

Screenshot 2023-09-05 at 13 46 47

@sashuk
Copy link
Contributor Author

sashuk commented Sep 5, 2023

@toptal-anvil ping reviewers

@sashuk sashuk merged commit 13bb62a into feature/base-spacing Sep 6, 2023
9 checks passed
@sashuk sashuk deleted the fx-4260-create-codemod-for-replacing-spacings branch September 6, 2023 09:09
sashuk added a commit that referenced this pull request Sep 20, 2023
sashuk added a commit that referenced this pull request Sep 22, 2023
sashuk added a commit that referenced this pull request Sep 25, 2023
sashuk added a commit that referenced this pull request Sep 25, 2023
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.

4 participants