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

Colors codemod types #396

Merged
merged 13 commits into from
Jan 15, 2024
Merged

Colors codemod types #396

merged 13 commits into from
Jan 15, 2024

Conversation

martimalek
Copy link
Contributor

@martimalek martimalek commented Nov 8, 2023

What:

Make the colors-to-css-vars codemod take into account Colors being used as a type instead of as a constant

Why:

When Colors was used as a type the codemod was not transforming it, which made the resulting file invalid

import { Colors } from '@freenow/wave';

export interface AnotherInterface { color?: Colors }

should be transformed to

import { ReadCssColorVariable } from '@freenow/wave';

// eslint-disable-next-line @typescript-eslint/ban-types you can remove this comment and only use the `ReadCssColorVariable` type after changing the bare colors to `getSemanticValue`
export interface AnotherInterface { color?: ReadCssColorVariable | (string & {}) }


How:

  • In colors-to-css-vars codemod, find usages of Colors as a type, replace them for the ReadCssColorVariable type and add it as an import
  • I've also added an early return checking if Colors is imported, so that in case it isn't we stop executing the codemod
  • Since the codemod adds an import for ReadCssColorVariable, I've exported the type from a essentials/index.ts

Checklist:

  • Add eslint-disable comment to Colors type replacement so it doesn't break linting
  • Ready to be merged

Closes #394

src/essentials/index.ts Outdated Show resolved Hide resolved
@martimalek martimalek requested a review from nlopin November 9, 2023 12:03
@martimalek
Copy link
Contributor Author

martimalek commented Nov 29, 2023

I've created the colors-codemod-add-eslint-comment branch with some tries on how to add the eslint disable comment to usages of Colors as a type.

I'll have to park this for a bit due to other priorities and I've created that branch in case we want to move forward with the current solution without the comments.

EDIT: I've finally had some time to implement this, the solution is in this branch/PR, so I've deleted the other one

@martimalek martimalek requested a review from nlopin January 12, 2024 13:58
Copy link
Contributor

@nlopin nlopin left a comment

Choose a reason for hiding this comment

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

Nice! I've added the type cleanup step to the migration guide

@martimalek martimalek merged commit 56bdd12 into next Jan 15, 2024
10 checks passed
@martimalek martimalek deleted the colors-codemod-types branch January 15, 2024 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants