Skip to content

Commit

Permalink
feat(HorizontalCell): add codemod
Browse files Browse the repository at this point in the history
  • Loading branch information
EldarMuhamethanov committed Oct 2, 2024
1 parent 7c42b48 commit 7a6bdf5
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { HorizontalCell, Image } from '@vkontakte/vkui';
import React from 'react';

const App = () => {
return (
<React.Fragment>
<HorizontalCell
header="Title"
subtitle="Subtitle"
extraSubtitle="Extra Subtitle"
size="m"
>
<Image size={88} borderRadius="l" />
</HorizontalCell>

<HorizontalCell
header={'Title'}
subtitle="Subtitle"
extraSubtitle="Extra Subtitle"
size="m"
>
<Image size={88} borderRadius="l" />
</HorizontalCell>
</React.Fragment>
);
};
Original file line number Diff line number Diff line change
@@ -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 (
(<React.Fragment>
<HorizontalCell
title="Title"
subtitle="Subtitle"
extraSubtitle="Extra Subtitle"
size="m"
>
<Image size={88} borderRadius="l" />
</HorizontalCell>
<HorizontalCell
title={'Title'}
subtitle="Subtitle"
extraSubtitle="Extra Subtitle"
size="m"
>
<Image size={88} borderRadius="l" />
</HorizontalCell>
</React.Fragment>)
);
};"
`;
12 changes: 12 additions & 0 deletions packages/codemods/src/transforms/v7/__tests__/horizontal-cell.ts
Original file line number Diff line number Diff line change
@@ -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}`),
);
});
18 changes: 18 additions & 0 deletions packages/codemods/src/transforms/v7/horizontal-cell.ts
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit 7a6bdf5

Please sign in to comment.