From 7a6bdf50d43fafb0d709f299bb49393f56d06ea8 Mon Sep 17 00:00:00 2001 From: "e.muhamethanov" Date: Wed, 2 Oct 2024 12:02:24 +0300 Subject: [PATCH] feat(HorizontalCell): add codemod --- .../horizontal-cell/basic.input.tsx | 26 +++++++++++++++++ .../__snapshots__/horizontal-cell.ts.snap | 29 +++++++++++++++++++ .../v7/__tests__/horizontal-cell.ts | 12 ++++++++ .../src/transforms/v7/horizontal-cell.ts | 18 ++++++++++++ 4 files changed, 85 insertions(+) create mode 100644 packages/codemods/src/transforms/v7/__testfixtures__/horizontal-cell/basic.input.tsx create mode 100644 packages/codemods/src/transforms/v7/__tests__/__snapshots__/horizontal-cell.ts.snap create mode 100644 packages/codemods/src/transforms/v7/__tests__/horizontal-cell.ts create mode 100644 packages/codemods/src/transforms/v7/horizontal-cell.ts diff --git a/packages/codemods/src/transforms/v7/__testfixtures__/horizontal-cell/basic.input.tsx b/packages/codemods/src/transforms/v7/__testfixtures__/horizontal-cell/basic.input.tsx new file mode 100644 index 0000000000..5e24dd4ad3 --- /dev/null +++ b/packages/codemods/src/transforms/v7/__testfixtures__/horizontal-cell/basic.input.tsx @@ -0,0 +1,26 @@ +import { HorizontalCell, Image } from '@vkontakte/vkui'; +import React from 'react'; + +const App = () => { + return ( + + + + + + + + + + ); +}; diff --git a/packages/codemods/src/transforms/v7/__tests__/__snapshots__/horizontal-cell.ts.snap b/packages/codemods/src/transforms/v7/__tests__/__snapshots__/horizontal-cell.ts.snap new file mode 100644 index 0000000000..722097ce58 --- /dev/null +++ b/packages/codemods/src/transforms/v7/__tests__/__snapshots__/horizontal-cell.ts.snap @@ -0,0 +1,29 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`horizontal-cell transforms correctly 1`] = ` +"import { HorizontalCell, Image } from '@vkontakte/vkui'; +import React from 'react'; + +const App = () => { + return ( + ( + + + + + + + ) + ); +};" +`; diff --git a/packages/codemods/src/transforms/v7/__tests__/horizontal-cell.ts b/packages/codemods/src/transforms/v7/__tests__/horizontal-cell.ts new file mode 100644 index 0000000000..a9bb8cb125 --- /dev/null +++ b/packages/codemods/src/transforms/v7/__tests__/horizontal-cell.ts @@ -0,0 +1,12 @@ +jest.autoMockOff(); + +import { defineSnapshotTestFromFixture } from '../../../testHelpers/testHelper'; + +const name = 'horizontal-cell'; +const fixtures = ['basic'] as const; + +describe(name, () => { + fixtures.forEach((test) => + defineSnapshotTestFromFixture(__dirname, name, global.TRANSFORM_OPTIONS, `${name}/${test}`), + ); +}); diff --git a/packages/codemods/src/transforms/v7/horizontal-cell.ts b/packages/codemods/src/transforms/v7/horizontal-cell.ts new file mode 100644 index 0000000000..91a9df8b44 --- /dev/null +++ b/packages/codemods/src/transforms/v7/horizontal-cell.ts @@ -0,0 +1,18 @@ +import { API, FileInfo } from 'jscodeshift'; +import { getImportInfo, renameProp } from '../../codemod-helpers'; +import { JSCodeShiftOptions } from '../../types'; + +export const parser = 'tsx'; + +export default function transformer(file: FileInfo, api: API, options: JSCodeShiftOptions) { + const { alias } = options; + const j = api.jscodeshift; + const source = j(file.source); + const { localName } = getImportInfo(j, file, 'HorizontalCell', alias); + + if (localName) { + renameProp(j, source, localName, { header: 'title' }); + } + + return source.toSource(); +}