Skip to content

Commit

Permalink
Clean up comments
Browse files Browse the repository at this point in the history
  • Loading branch information
stephl3 committed Oct 22, 2024
1 parent fab3612 commit 9133382
Show file tree
Hide file tree
Showing 17 changed files with 73 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ export const App = () => {

const Test = () => {
return (
/* Please update manually */
/* Please manually update from prop: propToRemove to prop: propToUpdate */
<MyComponent propToRemove="value2" {...props} />
);
};

const TestTwo = () => {
return (
<>
{/* Please update manually */}
{/* Please manually update from prop: propToRemove to prop: propToUpdate */}
<MyComponent propToRemove="value2" {...props} />
</>
);
Expand All @@ -39,7 +39,7 @@ export const App = () => {
</MyComponent>
<MyComponent propToUpdate="value3" />
<MyComponent propToUpdate="value3" />
{/* Please update manually */}
{/* Please manually update from prop: propToRemove to prop: propToUpdate */}
<MyComponent propToRemove="value2" {...props} />
<MyComponent propToUpdate="value3" {...props} />
<MyComponent />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ export const App = () => {

const WrappedPopover = () => {
return (
/* Please update manually */
/* Please manually update from prop: usePortal to prop: renderMode */
<Popover usePortal={false} {...spreadProps} />
);
};

const DefaultWrappedPopover = () => {
return (
/* Please add manually */
/* Please manually add prop: usePortal */
<Popover {...spreadProps} />
);
};
Expand All @@ -62,7 +62,7 @@ export const App = () => {
<Child usePortal={false} />
</Popover>
<Popover renderMode="inline" />
{/* Please update manually */}
{/* Please manually update from prop: usePortal to prop: renderMode */}
<Popover usePortal={true} {...spreadProps} />
<WrappedPopover />
<DefaultWrappedPopover />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export const App = () => {
return (
<>
<Code usePortal />
<DatePicker usePortal={false} />
<GuideCue usePortal={true} />
<DatePicker />
<GuideCue />
<InfoSprinkle usePortal />
<InlineDefinition usePortal={false} />
<NumberInput usePortal={true} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ export const App = () => {

const WrappedInfoSprinkle = (props: any) => {
return (
/* Please remove manually */
/* Please manually remove prop: popoverZIndex */
/* Please manually remove prop: portalClassName */
/* Please manually remove prop: portalContainer */
/* Please manually remove prop: portalRef */
/* Please manually remove prop: scrollContainer */
/* Please manually remove prop: usePortal */
<InfoSprinkle usePortal={false} {...props} />
);
};
Expand All @@ -59,13 +64,12 @@ export const App = () => {
<InfoSprinkle>
<Child usePortal={false} />
</InfoSprinkle>
{/* Please remove manually */}
{/* Please remove manually */}
{/* Please remove manually */}
{/* Please remove manually */}
{/* Please remove manually */}
{/* Please remove manually */}
{/* Please remove manually */}
{/* Please manually remove prop: popoverZIndex */}
{/* Please manually remove prop: portalClassName */}
{/* Please manually remove prop: portalContainer */}
{/* Please manually remove prop: portalRef */}
{/* Please manually remove prop: scrollContainer */}
{/* Please manually remove prop: usePortal */}
<InfoSprinkle usePortal={true} {...spreadProps} />
<WrappedInfoSprinkle />
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const App = () => {

const WrappedCopyable = (props: any) => {
return (
/* Please remove manually */
/* Please manually remove prop: shouldTooltipUsePortal */
<Copyable shouldTooltipUsePortal={false} {...props} />
);
};
Expand All @@ -28,13 +28,7 @@ export const App = () => {
<Copyable>
<Child shouldTooltipUsePortal={false} />
</Copyable>
{/* Please remove manually */}
{/* Please remove manually */}
{/* Please remove manually */}
{/* Please remove manually */}
{/* Please remove manually */}
{/* Please remove manually */}
{/* Please remove manually */}
{/* Please manually remove prop: shouldTooltipUsePortal */}
<Copyable shouldTooltipUsePortal={true} {...spreadProps} />
<WrappedCopyable />
</>
Expand Down
33 changes: 17 additions & 16 deletions tools/codemods/src/codemods/popover-v12/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,29 @@ const componentNamesForConsolidation = [
'Select',
'SplitButton',
'Tooltip',
] as const;

const componentNamesForRemoval = [
'Code',
'Copyable',
'DatePicker',
'GuideCue',
'InfoSprinkle',
'InlineDefinition',
'NumberInput',
'SearchInput',
] as const;
];

const propNamesToRemove = [
'popoverZIndex',
'portalClassName',
'portalContainer',
'portalRef',
'scrollContainer',
'shouldTooltipUsePortal',
'usePortal',
] as const;
];

const componentNamesWithPropsToRemoveMap: Record<string, Array<string>> = {
Code: propNamesToRemove.filter(propName => propName !== 'portalRef'),
Copyable: ['shouldTooltipUsePortal'],
DatePicker: propNamesToRemove.filter(propName => propName !== 'usePortal'),
GuideCue: propNamesToRemove.filter(propName => propName !== 'usePortal'),
InfoSprinkle: propNamesToRemove,
InlineDefinition: propNamesToRemove,
NumberInput: propNamesToRemove,
SearchInput: propNamesToRemove.filter(
propName => propName !== 'popoverZIndex',
),
};

/**
* Transformer function that:
Expand Down Expand Up @@ -89,13 +90,13 @@ export default function transformer(file: FileInfo, { jscodeshift: j }: API) {
});
});

componentNamesForRemoval.forEach(componentName => {
Object.keys(componentNamesWithPropsToRemoveMap).forEach(componentName => {
const elements = source.findJSXElements(componentName);

if (elements.length === 0) return;

elements.forEach(element => {
propNamesToRemove.forEach(propName => {
componentNamesWithPropsToRemoveMap[componentName].forEach(propName => {
removeJSXAttributes({
j,
element,
Expand Down
6 changes: 3 additions & 3 deletions tools/codemods/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const MIGRATOR_ERROR = {
manualAdd: 'Please add manually',
manualRemove: 'Please remove manually',
manualUpdate: 'Please update manually',
manualAdd: 'Please manually add',
manualRemove: 'Please manually remove',
manualUpdate: 'Please manually update',
};
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ export function addJSXAttributes({
}

if (hasSpreadOperator) {
insertJSXComment(j, element, MIGRATOR_ERROR.manualAdd);
insertJSXComment(
j,
element,
`${MIGRATOR_ERROR.manualAdd} prop: ${propName}`,
);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const App = () => {
Hello
<Child />
</MyComponent>
{/* Please add manually */}
{/* Please manually add prop: prop */}
<MyComponent {...spreadProps} />
<MyComponent prop={true} />
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const App = () => {
Hello
<Child prop="child-value" />
</MyComponent>
{/* Please add manually */}
{/* Please manually add prop: prop */}
<MyComponent {...spreadProps} />
<MyComponent prop="existing-value">Hello</MyComponent>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const App = () => {
Hello
<Child prop={456} />
</MyComponent>
{/* Please add manually */}
{/* Please manually add prop: prop */}
<MyComponent {...spreadProps} />
<MyComponent prop={789}>Hello</MyComponent>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const App = () => {
Hello
<Child prop="child-value" />
</MyComponent>
{/* Please add manually */}
{/* Please manually add prop: prop */}
<MyComponent {...spreadProps} />
<MyComponent prop="existing-value">Hello</MyComponent>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ export function consolidateJSXAttributes({

// if fromProp value is variable of the same name then return early since we don't know the value
if (oldValue === propToRemove) {
insertJSXComment(j, element, MIGRATOR_ERROR.manualUpdate);
insertJSXComment(
j,
element,
`${MIGRATOR_ERROR.manualUpdate} from prop: ${propToRemove} to prop: ${propToUpdate}`,
);
return;
}

Expand All @@ -128,7 +132,11 @@ export function consolidateJSXAttributes({

// if the propToUpdate does not exist and there is a spread operator then return early since we don't know if the propToUpdate could be inside the spread
if (!_propToUpdate && hasSpreadOperator) {
insertJSXComment(j, element, MIGRATOR_ERROR.manualUpdate);
insertJSXComment(
j,
element,
`${MIGRATOR_ERROR.manualUpdate} from prop: ${propToRemove} to prop: ${propToUpdate}`,
);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ export const App = (disabled?: boolean) => {
<Child state="value" disabled={true} />
<MyComponent state="disabled" />
</MyComponent>
{/* Please update manually */}
{/* Please manually update from prop: disabled to prop: state */}
<MyComponent disabled={true} {...props} />
<MyComponent state="disabled" {...props} />
{/* Please update manually */}
{/* Please manually update from prop: disabled to prop: state */}
<MyComponent disabled={disabled} />
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ export const App = (propToRemove?: string) => {

const Test = () => {
return (
/* Please update manually */
/* Please manually update from prop: propToRemove to prop: propToUpdate */
<MyComponent propToRemove="value2" {...props} />
);
};

const TestTwo = () => {
return (
<>
{/* Please update manually */}
{/* Please manually update from prop: propToRemove to prop: propToUpdate */}
<MyComponent propToRemove="value2" {...props} />
</>
);
Expand All @@ -39,11 +39,11 @@ export const App = (propToRemove?: string) => {
</MyComponent>
<MyComponent propToUpdate="value3" />
<MyComponent propToUpdate="value3" />
{/* Please update manually */}
{/* Please manually update from prop: propToRemove to prop: propToUpdate */}
<MyComponent propToRemove="value2" {...props} />
<MyComponent propToUpdate="value3" {...props} />
<MyComponent />
{/* Please update manually */}
{/* Please manually update from prop: propToRemove to prop: propToUpdate */}
<MyComponent propToRemove={propToRemove} />
<Test />
<TestTwo />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ export function removeJSXAttributes({
);

if (hasSpreadOperator) {
insertJSXComment(j, element, MIGRATOR_ERROR.manualRemove);
insertJSXComment(
j,
element,
`${MIGRATOR_ERROR.manualRemove} prop: ${propName}`,
);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const App = () => {
Hello
<Child />
</MyComponent>
{/* Please remove manually */}
{/* Please manually remove prop: prop */}
<MyComponent {...spreadProps} />
<MyComponent />
<MyComponent />
Expand Down

0 comments on commit 9133382

Please sign in to comment.