Skip to content

Commit

Permalink
Feat(codemods): Add Tabs props rename codemod #DS-1096
Browse files Browse the repository at this point in the history
Rename TabItem prop `forTab` to `forTabPane`.
Rename TabPane prop `tabId` to `id`.
  • Loading branch information
crishpeen committed May 9, 2024
1 parent 0d3564f commit 3e4ae81
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
// @ts-ignore: No declaration -- The library is not installed; we don't need to install it for fixtures.
import { TabItem, TabPane } from '@lmc-eu/spirit-web-react';

export const MyComponent = () => (
<>
<TabItem forTab="tab1" data-test="test" />
<TabPane tabId="tab1" />
</>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
// @ts-ignore: No declaration -- The library is not installed; we don't need to install it for fixtures.
import { TabItem, TabPane } from '@lmc-eu/spirit-web-react';

export const MyComponent = () => (
<>
<TabItem forTabPane="tab1" data-test="test" />
<TabPane id="tab1" />
</>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { testTransform } from '../../../../../tests/testUtils';

testTransform(__dirname, 'tabs-tabitem-tabpane-props');
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { API, FileInfo } from 'jscodeshift';

const transform = (fileInfo: FileInfo, api: API) => {
const j = api.jscodeshift;
const root = j(fileInfo.source);

// Find JSX elements <TabItem> and update `forTab` to `forTabPane`
root
.find(j.JSXOpeningElement, { name: { type: 'JSXIdentifier', name: 'TabItem' } })
.find(j.JSXAttribute, { name: { type: 'JSXIdentifier', name: 'forTab' } })
.forEach((path) => {
j(path).replaceWith(j.jsxAttribute(j.jsxIdentifier('forTabPane'), path.node.value));
});

// Find JSX elements <TabPane> and update `tabId` to `id`
root
.find(j.JSXOpeningElement, { name: { type: 'JSXIdentifier', name: 'TabPane' } })
.find(j.JSXAttribute, { name: { type: 'JSXIdentifier', name: 'tabId' } })
.forEach((path) => {
j(path).replaceWith(j.jsxAttribute(j.jsxIdentifier('id'), path.node.value));
});

return root.toSource({ quote: 'single' });
};

export default transform;

0 comments on commit 3e4ae81

Please sign in to comment.