Skip to content

Commit

Permalink
fix: update codemods to retain empty lines (#5265)
Browse files Browse the repository at this point in the history
* refactor(codemods): clean up transform utils

* fix(codemods): retain empty lines
  • Loading branch information
HeartSquared authored Nov 12, 2024
1 parent a1c0a3f commit 034fbf2
Show file tree
Hide file tree
Showing 46 changed files with 350 additions and 200 deletions.
5 changes: 5 additions & 0 deletions .changeset/stupid-experts-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kaizen/components": patch
---

Update codemods to retain empty lines.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ module.exports = {
},
},
{
files: ["**/bin/**", "vitest.setup.ts"],
files: ["**/bin/**", "**/codemods/**", "vitest.setup.ts"],
rules: {
"no-console": "off",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { transformComponentsInDir } from "../utils"
import { transformBrandMomentMoodToVariant } from "./transformBrandMomentMoodToVariant"

const migrateBrandMomentMoodToVariant = (): void => {
// eslint-disable-next-line no-console
console.log(
" ~(-_- ~) Running BrandMoment mood to variant transformer (~ -_-)~"
"~(-_- ~) Running BrandMoment mood to variant transformer (~ -_-)~"
)
const targetDir = process.argv[2]
if (!targetDir) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { parseJsx } from "../__tests__/utils"
import { transformSource, printAst, TransformConfig } from "../utils"
import {
printAst,
transformSourceForTagName,
type TransformSourceForTagNameArgs,
} from "../utils"
import { transformBrandMomentMoodToVariant } from "./transformBrandMomentMoodToVariant"

const transformBrandMoment = (
sourceFile: TransformConfig["sourceFile"]
sourceFile: TransformSourceForTagNameArgs["sourceFile"]
): string =>
transformSource({
transformSourceForTagName({
sourceFile,
astTransformer: transformBrandMomentMoodToVariant,
tagName: "BrandMoment",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { transformComponentsInDir } from "../utils"
import { transformCardVariantToColor } from "./transformCardVariantToColor"

const migrateCardVariantToColor = (): void => {
// eslint-disable-next-line no-console
console.log(" ~(-_- ~) Running Card variant to color transformer (~ -_-)~")
console.log("~(-_- ~) Running Card variant to color transformer (~ -_-)~")
const targetDir = process.argv[2]
if (!targetDir) {
process.exit(1)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { parseJsx } from "../__tests__/utils"
import { transformSource, printAst, TransformConfig } from "../utils"
import {
printAst,
transformSourceForTagName,
type TransformSourceForTagNameArgs,
} from "../utils"
import { transformCardVariantToColor } from "./transformCardVariantToColor"

const transformCard = (sourceFile: TransformConfig["sourceFile"]): string =>
transformSource({
const transformCard = (
sourceFile: TransformSourceForTagNameArgs["sourceFile"]
): string =>
transformSourceForTagName({
sourceFile,
astTransformer: transformCardVariantToColor,
tagName: "Card",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { transformComponentsInDir } from "../utils"
import { transformConfirmationModalMoodsToVariant } from "./transformConfirmationModalMoodsToVariant"

const run = (): void => {
// eslint-disable-next-line no-console
console.log(" ~(-_- ~) Running ConfirmationModal transformer (~ -_-)~")
console.log("~(-_- ~) Running ConfirmationModal transformer (~ -_-)~")
const targetDir = process.argv[2]
if (!targetDir) {
process.exit(1)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parseJsx } from "../__tests__/utils"
import { transformSource, printAst } from "../utils"
import { transformSourceForTagName, printAst } from "../utils"
import { transformConfirmationModalMoodsToVariant } from "./transformConfirmationModalMoodsToVariant"

describe("transformConfirmationModalMoodsToVariant", () => {
Expand All @@ -10,7 +10,7 @@ describe("transformConfirmationModalMoodsToVariant", () => {
const outputAst = parseJsx(`
export const TestComponent = () => <ConfirmationModal variant="success"/>
`)
const transformed = transformSource({
const transformed = transformSourceForTagName({
sourceFile: inputAst,
astTransformer: transformConfirmationModalMoodsToVariant,
tagName: "ConfirmationModal",
Expand All @@ -25,7 +25,7 @@ describe("transformConfirmationModalMoodsToVariant", () => {
const outputAst = parseJsx(`
export const TestComponent = () => <ConfirmationModal variant="warning"/>
`)
const transformed = transformSource({
const transformed = transformSourceForTagName({
sourceFile: inputAst,
astTransformer: transformConfirmationModalMoodsToVariant,
tagName: "ConfirmationModal",
Expand All @@ -40,7 +40,7 @@ describe("transformConfirmationModalMoodsToVariant", () => {
const outputAst = parseJsx(`
export const TestComponent = () => <ConfirmationModal variant="warning" id="123"/>
`)
const transformed = transformSource({
const transformed = transformSourceForTagName({
sourceFile: inputAst,
astTransformer: transformConfirmationModalMoodsToVariant,
tagName: "ConfirmationModal",
Expand All @@ -55,7 +55,7 @@ describe("transformConfirmationModalMoodsToVariant", () => {
const outputAst = parseJsx(`
export const TestComponent = () => <div><ConfirmationModal variant="success"/><ConfirmationModal variant="warning"/></div>
`)
const transformed = transformSource({
const transformed = transformSourceForTagName({
sourceFile: inputAst,
astTransformer: transformConfirmationModalMoodsToVariant,
tagName: "ConfirmationModal",
Expand All @@ -70,7 +70,7 @@ describe("transformConfirmationModalMoodsToVariant", () => {
const outputAst = parseJsx(`
export const TestComponent = () => <div><ConfirmationModal variant="success"/><ConfirmationModal variant="cautionary"/><ConfirmationModal variant="success"/></div>
`)
const transformed = transformSource({
const transformed = transformSourceForTagName({
sourceFile: inputAst,
astTransformer: transformConfirmationModalMoodsToVariant,
tagName: "ConfirmationModal",
Expand All @@ -85,7 +85,7 @@ describe("transformConfirmationModalMoodsToVariant", () => {
const outputAst = parseJsx(`
export const TestComponent = () => <div><ConfirmationModal variant="success"/></div>
`)
const transformed = transformSource({
const transformed = transformSourceForTagName({
sourceFile: inputAst,
astTransformer: transformConfirmationModalMoodsToVariant,
tagName: "ConfirmationModal",
Expand All @@ -100,7 +100,7 @@ describe("transformConfirmationModalMoodsToVariant", () => {
const outputAst = parseJsx(`
export const TestComponent = () => <div><ConfirmationModal variant={confirmationModalVariable}/></div>
`)
const transformed = transformSource({
const transformed = transformSourceForTagName({
sourceFile: inputAst,
astTransformer: transformConfirmationModalMoodsToVariant,
tagName: "ConfirmationModal",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { transformComponentsInDir } from "../utils"
import { transformEmptyStateIllustrationTypeToVariant } from "./transformEmptyStateIllustrationTypeToVariant"

const migrateEmptyStateIllustrationTypeToVariant = (): void => {
// eslint-disable-next-line no-console
console.log(
" ~(-_- ~) Running EmptyState illustrationType to variant transformer (~ -_-)~"
"~(-_- ~) Running EmptyState illustrationType to variant transformer (~ -_-)~"
)
const targetDir = process.argv[2]
if (!targetDir) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { parseJsx } from "../__tests__/utils"
import { transformSource, printAst, TransformConfig } from "../utils"
import {
printAst,
transformSourceForTagName,
type TransformSourceForTagNameArgs,
} from "../utils"
import { transformEmptyStateIllustrationTypeToVariant } from "./transformEmptyStateIllustrationTypeToVariant"

const transformEmptyState = (
sourceFile: TransformConfig["sourceFile"]
sourceFile: TransformSourceForTagNameArgs["sourceFile"]
): string =>
transformSource({
transformSourceForTagName({
sourceFile,
astTransformer: transformEmptyStateIllustrationTypeToVariant,
tagName: "EmptyState",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { transformNotificationTypeToVariant } from "../migrateNotificationTypeToVariant"
import { transformComponentsInDir } from "../utils"
/** This is here as a script runner that migrates GlobalNotification variant to their color equivalent */

const migrateGlobalNotificationTypeToVariant = (): void => {
// eslint-disable-next-line no-console
console.log(" ~(-_- ~) Running GlobalNotification transformer (~ -_-)~")
console.log("~(-_- ~) Running GlobalNotification transformer (~ -_-)~")
const targetDir = process.argv[2]
if (!targetDir) {
process.exit(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { transformComponentsInDir } from "../utils"
import { transformInformationTileMoodToVariant } from "./transformInformationTileMoodToVariant"

const migrateInformationTileMoodToVariant = (): void => {
// eslint-disable-next-line no-console
console.log(
" ~(-_- ~) Running InformationTile mood to variant transformer (~ -_-)~"
"~(-_- ~) Running InformationTile mood to variant transformer (~ -_-)~"
)
const targetDir = process.argv[2]
if (!targetDir) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { parseJsx } from "../__tests__/utils"
import { transformSource, printAst, TransformConfig } from "../utils"
import {
printAst,
transformSourceForTagName,
type TransformSourceForTagNameArgs,
} from "../utils"
import { transformInformationTileMoodToVariant } from "./transformInformationTileMoodToVariant"

const transformInformationTile = (
sourceFile: TransformConfig["sourceFile"]
sourceFile: TransformSourceForTagNameArgs["sourceFile"]
): string =>
transformSource({
transformSourceForTagName({
sourceFile,
astTransformer: transformInformationTileMoodToVariant,
tagName: "InformationTile",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { transformNotificationTypeToVariant } from "../migrateNotificationTypeToVariant"
import { transformComponentsInDir } from "../utils"
/** This is here as a script runner that migrates InlineNotification variant to their color equivalent */

const migrateInlineNotificationTypeToVariant = (): void => {
// eslint-disable-next-line no-console
console.log(" ~(-_- ~) Running InlineNotification transformer (~ -_-)~")
console.log("~(-_- ~) Running InlineNotification transformer (~ -_-)~")
const targetDir = process.argv[2]
if (!targetDir) {
process.exit(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { transformComponentsInDir } from "../utils"
import { transformMultiActionTileMoodToVariant } from "./transformMultiActionTileMoodToVariant"

const migrateMultiActionTileMoodToVariant = (): void => {
// eslint-disable-next-line no-console
console.log(
" ~(-_- ~) Running MultiActionTile mood to variant transformer (~ -_-)~"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { parseJsx } from "../__tests__/utils"
import { transformSource, printAst, TransformConfig } from "../utils"
import {
printAst,
transformSourceForTagName,
type TransformSourceForTagNameArgs,
} from "../utils"
import { transformMultiActionTileMoodToVariant } from "./transformMultiActionTileMoodToVariant"

const transformMultiActionTile = (
sourceFile: TransformConfig["sourceFile"]
sourceFile: TransformSourceForTagNameArgs["sourceFile"]
): string =>
transformSource({
transformSourceForTagName({
sourceFile,
astTransformer: transformMultiActionTileMoodToVariant,
tagName: "MultiActionTile",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parseJsx } from "../__tests__/utils"
import { transformSource, printAst } from "../utils"
import { transformSourceForTagName, printAst } from "../utils"
import { transformNotificationTypeToVariant } from "./migrateNotificationTypeToVariant"

describe("transformNotificationTypeToVariant", () => {
Expand All @@ -10,7 +10,7 @@ describe("transformNotificationTypeToVariant", () => {
const outputAst = parseJsx(`
export const TestComponent = () => <InlineNotification variant="success">Test</InlineNotification>
`)
const transformed = transformSource({
const transformed = transformSourceForTagName({
sourceFile: inputAst,
astTransformer: transformNotificationTypeToVariant,
tagName: "InlineNotification",
Expand All @@ -25,7 +25,7 @@ describe("transformNotificationTypeToVariant", () => {
const outputAst = parseJsx(`
export const TestComponent = () => <GlobalNotification variant="success">Test</GlobalNotification>
`)
const transformed = transformSource({
const transformed = transformSourceForTagName({
sourceFile: inputAst,
astTransformer: transformNotificationTypeToVariant,
tagName: "GlobalNotification",
Expand All @@ -40,7 +40,7 @@ describe("transformNotificationTypeToVariant", () => {
const outputAst = parseJsx(`
export const TestComponent = () => <ToastNotification variant="success">Test</ToastNotification>
`)
const transformed = transformSource({
const transformed = transformSourceForTagName({
sourceFile: inputAst,
astTransformer: transformNotificationTypeToVariant,
tagName: "ToastNotification",
Expand All @@ -55,7 +55,7 @@ describe("transformNotificationTypeToVariant", () => {
const outputAst = parseJsx(`
export const TestComponent = () => <InlineNotification variant="informative">Test</InlineNotification>
`)
const transformed = transformSource({
const transformed = transformSourceForTagName({
sourceFile: inputAst,
astTransformer: transformNotificationTypeToVariant,
tagName: "InlineNotification",
Expand All @@ -69,7 +69,7 @@ describe("transformNotificationTypeToVariant", () => {
const outputAst = parseJsx(`
export const TestComponent = () => <InlineNotification variant="cautionary">Test</InlineNotification>
`)
const transformed = transformSource({
const transformed = transformSourceForTagName({
sourceFile: inputAst,
astTransformer: transformNotificationTypeToVariant,
tagName: "InlineNotification",
Expand All @@ -83,7 +83,7 @@ describe("transformNotificationTypeToVariant", () => {
const outputAst = parseJsx(`
export const TestComponent = () => <InlineNotification variant="security">Test</InlineNotification>
`)
const transformed = transformSource({
const transformed = transformSourceForTagName({
sourceFile: inputAst,
astTransformer: transformNotificationTypeToVariant,
tagName: "InlineNotification",
Expand All @@ -97,7 +97,7 @@ describe("transformNotificationTypeToVariant", () => {
const outputAst = parseJsx(`
export const TestComponent = () => <InlineNotification variant="warning">Test</InlineNotification>
`)
const transformed = transformSource({
const transformed = transformSourceForTagName({
sourceFile: inputAst,
astTransformer: transformNotificationTypeToVariant,
tagName: "InlineNotification",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { transformComponentsInDir } from "../utils"
import { transformProgressBarMoodToColor } from "./transformProgressBarMoodToColor"

const migrateProgressBarMoodToColor = (): void => {
// eslint-disable-next-line no-console
console.log(
" ~(-_- ~) Running ProgressBar mood to color transformer (~ -_-)~"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { parseJsx } from "../__tests__/utils"
import { transformSource, printAst, TransformConfig } from "../utils"
import {
printAst,
transformSourceForTagName,
type TransformSourceForTagNameArgs,
} from "../utils"
import { transformProgressBarMoodToColor } from "./transformProgressBarMoodToColor"

const transformProgressBar = (
sourceFile: TransformConfig["sourceFile"]
sourceFile: TransformSourceForTagNameArgs["sourceFile"]
): string =>
transformSource({
transformSourceForTagName({
sourceFile,
astTransformer: transformProgressBarMoodToColor,
tagName: "ProgressBar",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { transformNotificationTypeToVariant } from "../migrateNotificationTypeToVariant"
import { transformComponentsInDir } from "../utils"
/** This is here as a script runner that migrates ToastNotification variant to their color equivalent */

const migrateToastNotificationTypeToVariant = (): void => {
// eslint-disable-next-line no-console
console.log(" ~(-_- ~) Running ToastNotification transformer (~ -_-)~")
const targetDir = process.argv[2]
if (!targetDir) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { transformComponentsInDir } from "../utils"
import { transformWellVariantToColor } from "./transformWellVariantToColor"
/** This is here as a script runner that migrates Well variant to their color equivalent */

const migrateWellVariantToColor = (): void => {
// eslint-disable-next-line no-console
console.log(" ~(-_- ~) Running Well transformer (~ -_-)~")
const targetDir = process.argv[2]
if (!targetDir) {
Expand Down
Loading

0 comments on commit 034fbf2

Please sign in to comment.