Skip to content

Commit

Permalink
feat: enhance codemods
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackySoul committed Nov 5, 2024
1 parent d59908b commit cff98b2
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const App = () => {
</CellButton>

{/* do nothing 2 */}
<CellButton centered>
<CellButton centered expandable="auto">
Создать что-нибудь
</CellButton>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { PanelSpinner } from '@vkontakte/vkui';
import React from 'react';

const App = () => {
return (
<React.Fragment>
<PanelSpinner size="large" />
<PanelSpinner size="medium" />
<PanelSpinner size="regular" />
<PanelSpinner size={"small"} />
</React.Fragment>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const App = () => {
Создать что-нибудь
</CellButton>
{/* do nothing 2 */}
<CellButton centered>
<CellButton centered chevron="auto">
Создать что-нибудь
</CellButton>
{/* rename subhead -> overtitle */}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`panel-spinner transforms correctly 1`] = `
"import { PanelSpinner } from '@vkontakte/vkui';
import React from 'react';
const App = () => {
return (
(<React.Fragment>
<PanelSpinner size="xl" />
<PanelSpinner size="l" />
<PanelSpinner size="m" />
<PanelSpinner size={"s"} />
</React.Fragment>)
);
};"
`;
12 changes: 12 additions & 0 deletions packages/codemods/src/transforms/v7/__tests__/panel-spinner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
jest.autoMockOff();

import { defineSnapshotTestFromFixture } from '../../../testHelpers/testHelper';

const name = 'panel-spinner';
const fixtures = ['basic'] as const;

describe(name, () => {
fixtures.forEach((test) =>
defineSnapshotTestFromFixture(__dirname, name, global.TRANSFORM_OPTIONS, `${name}/${test}`),
);
});
2 changes: 1 addition & 1 deletion packages/codemods/src/transforms/v7/banner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function transformer(file: FileInfo, api: API, options: JSCodeShi
}
report(
api,
`Manual changes required for ${localName}'s "after" (previously "asideMode") prop. Need to change "expand" value to "chevron"`,
`Manual changes required for ${localName}'s "after" (previously "asideMode") prop. Need to change "expand" value to "chevron".`,
);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/codemods/src/transforms/v7/cell-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function transformer(file: FileInfo, api: API, options: JSCodeShi
return source.toSource();
}

renameProp(j, source, localName, { subhead: 'overTitle' });
renameProp(j, source, localName, { subhead: 'overTitle', expandable: 'chevron' });

const attributeToReplace = 'mode';
const newAttributeName = 'appearance';
Expand Down
33 changes: 33 additions & 0 deletions packages/codemods/src/transforms/v7/panel-spinner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { API, FileInfo } from 'jscodeshift';
import { remapSizePropValue } from './common/remapSizePropValue';
import { getImportInfo } from '../../codemod-helpers';
import { JSCodeShiftOptions } from '../../types';

export const parser = 'tsx';

const componentName = 'PanelSpinner';
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, componentName, alias);

if (!localName) {
return source.toSource();
}

remapSizePropValue({
j,
api,
source,
componentName: localName,
sizesMap: {
large: 'xl',
medium: 'l',
regular: 'm',
small: 's',
},
});

return source.toSource();
}
2 changes: 1 addition & 1 deletion packages/codemods/src/transforms/v7/subnavigation-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function replaceModeToFixed(j: JSCodeshift, source: Collection, api: API, localN
if (value === null) {
report(
api,
`: ${localName} has been changed. Manual changes required: change prop mode to flag fixed`,
`: ${localName} has been changed. Manual changes required: change prop mode to flag fixed.`,
);
return;
}
Expand Down

0 comments on commit cff98b2

Please sign in to comment.