Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add more codemods #6340

Merged
merged 3 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { CardScroll } from '@vkontakte/vkui';
import React from 'react';

const App = () => {
return (
<React.Fragment>
<CardScroll withSpaces>{cards}</CardScroll>
<CardScroll withSpaces={false}>{cards}</CardScroll>
<CardScroll withSpaces={withSpaces}>{cards}</CardScroll>
</React.Fragment>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ const App = () => {
<ConfigProvider {...configProviderProps}>
<App />
</ConfigProvider>
<ConfigProvider platform="someAnotherPlatform">
<App />
</ConfigProvider>
</React.Fragment>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Gallery } from '@vkontakte/vkui';
import React from 'react';

const App = () => {
return (
<React.Fragment>
<Gallery isDraggable>{slides}</Gallery>
<Gallery isDraggable={false}>{slides}</Gallery>
</React.Fragment>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Image, ImageBase, Avatar as VKUIAvatar } from '@vkontakte/vkui';
import React from 'react';

const App = () => {
return (
<React.Fragment>
<Image src="image.svg" withBorder></Image>
<ImageBase withBorder={false} src="image.svg"></ImageBase>
<VKUIAvatar withBorder={true} />
</React.Fragment>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Placeholder } from '@vkontakte/vkui';
import React from 'react';

const App = () => {
return (
<React.Fragment>
<Placeholder withPadding>Placeholder</Placeholder>
<Placeholder withPadding={true}>Placeholder</Placeholder>
<Placeholder withPadding={false}>Placeholder</Placeholder>
</React.Fragment>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { PopoutWrapper } from '@vkontakte/vkui';
import React from 'react';

const App = () => {
return (
<React.Fragment>
<PopoutWrapper hasMask />
<PopoutWrapper hasMask={false} />
</React.Fragment>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ChipsSelect, CustomSelect, Select as VKUISelect } from '@vkontakte/vkui';
import React from 'react';

const App = () => {
return (
<React.Fragment>
<VKUISelect fixDropdownWidth options={options} />
<CustomSelect fixDropdownWidth={false} options={options} />
<ChipsSelect fixDropdownWidth={true} options={options} />
</React.Fragment>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Tabbar } from '@vkontakte/vkui';
import React from 'react';

const App = () => {
return (
<React.Fragment>
<Tabbar shadow />
<Tabbar shadow={false} />
</React.Fragment>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`card-scroll transforms correctly 1`] = `
"import { CardScroll } from '@vkontakte/vkui';
import React from 'react';

const App = () => {
return (
<React.Fragment>
<CardScroll>{cards}</CardScroll>
<CardScroll noSpaces>{cards}</CardScroll>
<CardScroll withSpaces={withSpaces}>{cards}</CardScroll>
BlackySoul marked this conversation as resolved.
Show resolved Hide resolved
</React.Fragment>
);
};"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ const App = () => {
<ConfigProvider {...configProviderProps}>
<App />
</ConfigProvider>
<ConfigProvider tokensClassNames={{
light: "vkui--someAnotherPlatform--light",
dark: "vkui--someAnotherPlatform--dark"
}}>
<App />
</ConfigProvider>
</React.Fragment>
);
};"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`gallery transforms correctly 1`] = `
"import { Gallery } from '@vkontakte/vkui';
import React from 'react';

const App = () => {
return (
<React.Fragment>
<Gallery>{slides}</Gallery>
<Gallery dragDisabled>{slides}</Gallery>
</React.Fragment>
);
};"
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`image-base transforms correctly 1`] = `
"import { Image, ImageBase, Avatar as VKUIAvatar } from '@vkontakte/vkui';
import React from 'react';

const App = () => {
return (
<React.Fragment>
<Image src="image.svg"></Image>
<ImageBase noBorder src="image.svg"></ImageBase>
<VKUIAvatar />
</React.Fragment>
);
};"
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`placeholder transforms correctly 1`] = `
"import { Placeholder } from '@vkontakte/vkui';
import React from 'react';

const App = () => {
return (
<React.Fragment>
<Placeholder>Placeholder</Placeholder>
<Placeholder>Placeholder</Placeholder>
<Placeholder noPadding>Placeholder</Placeholder>
</React.Fragment>
);
};"
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`popout-wrapper transforms correctly 1`] = `
"import { PopoutWrapper } from '@vkontakte/vkui';
import React from 'react';

const App = () => {
return (
<React.Fragment>
<PopoutWrapper />
<PopoutWrapper noBackground />
</React.Fragment>
);
};"
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`select transforms correctly 1`] = `
"import { ChipsSelect, CustomSelect, Select as VKUISelect } from '@vkontakte/vkui';
import React from 'react';

const App = () => {
return (
<React.Fragment>
<VKUISelect options={options} />
<CustomSelect dropdownAutoWidth options={options} />
<ChipsSelect options={options} />
</React.Fragment>
);
};"
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`tabbar transforms correctly 1`] = `
"import { Tabbar } from '@vkontakte/vkui';
import React from 'react';

const App = () => {
return (
<React.Fragment>
<Tabbar />
<Tabbar plain />
</React.Fragment>
);
};"
`;
12 changes: 12 additions & 0 deletions packages/codemods/src/transforms/__tests__/card-scroll.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
jest.autoMockOff();

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

const name = 'card-scroll';
const fixtures = ['basic'] as const;

describe(name, () => {
fixtures.forEach((test) =>
defineSnapshotTestFromFixture(__dirname, name, global.TRANSFORM_OPTIONS, `${name}/${test}`),
);
});
12 changes: 12 additions & 0 deletions packages/codemods/src/transforms/__tests__/gallery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
jest.autoMockOff();

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

const name = 'gallery';
const fixtures = ['basic'] as const;

describe(name, () => {
fixtures.forEach((test) =>
defineSnapshotTestFromFixture(__dirname, name, global.TRANSFORM_OPTIONS, `${name}/${test}`),
);
});
12 changes: 12 additions & 0 deletions packages/codemods/src/transforms/__tests__/image-base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
jest.autoMockOff();

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

const name = 'image-base';
const fixtures = ['basic'] as const;

describe(name, () => {
fixtures.forEach((test) =>
defineSnapshotTestFromFixture(__dirname, name, global.TRANSFORM_OPTIONS, `${name}/${test}`),
);
});
12 changes: 12 additions & 0 deletions packages/codemods/src/transforms/__tests__/placeholder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
jest.autoMockOff();

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

const name = 'placeholder';
const fixtures = ['basic'] as const;

describe(name, () => {
fixtures.forEach((test) =>
defineSnapshotTestFromFixture(__dirname, name, global.TRANSFORM_OPTIONS, `${name}/${test}`),
);
});
12 changes: 12 additions & 0 deletions packages/codemods/src/transforms/__tests__/popout-wrapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
jest.autoMockOff();

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

const name = 'popout-wrapper';
const fixtures = ['basic'] as const;

describe(name, () => {
fixtures.forEach((test) =>
defineSnapshotTestFromFixture(__dirname, name, global.TRANSFORM_OPTIONS, `${name}/${test}`),
);
});
12 changes: 12 additions & 0 deletions packages/codemods/src/transforms/__tests__/select.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
jest.autoMockOff();

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

const name = 'select';
const fixtures = ['basic'] as const;

describe(name, () => {
fixtures.forEach((test) =>
defineSnapshotTestFromFixture(__dirname, name, global.TRANSFORM_OPTIONS, `${name}/${test}`),
);
});
12 changes: 12 additions & 0 deletions packages/codemods/src/transforms/__tests__/tabbar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
jest.autoMockOff();

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

const name = 'tabbar';
const fixtures = ['basic'] as const;

describe(name, () => {
fixtures.forEach((test) =>
defineSnapshotTestFromFixture(__dirname, name, global.TRANSFORM_OPTIONS, `${name}/${test}`),
);
});
37 changes: 37 additions & 0 deletions packages/codemods/src/transforms/card-scroll.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { API, FileInfo } from 'jscodeshift';
import { getImportInfo } 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, 'CardScroll', alias);

source
.find(
j.JSXOpeningElement,
(element) => element.name.type === 'JSXIdentifier' && element.name.name === localName,
)
.find(j.JSXAttribute, (attribute) => attribute.name.name === 'withSpaces')
.forEach((attribute) => {
const node = attribute.node;

if (!node.value) {
j(attribute).remove();
} else if (
node.value.type === 'JSXExpressionContainer' &&
node.value.expression.type === 'BooleanLiteral'
) {
if (node.value.expression.value) {
j(attribute).remove();
} else {
j(attribute).replaceWith(j.jsxAttribute(j.jsxIdentifier('noSpaces')));
}
}
});

return source.toSource();
}
Loading