-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Codemod: remove Section and Items imports if not used elsewhere in file #6908
Conversation
@@ -68,7 +67,6 @@ const items = [ | |||
|
|||
exports[`Dynamic - Renames key to id 1`] = ` | |||
"import { MenuItem, Menu, MenuTrigger, SubmenuTrigger, Button } from "@react-spectrum/s2"; | |||
import { Item } from '@adobe/react-spectrum'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a lot of cases where we're removing the Item or Section from tests. This seems like a great change.
I found the two following tests where we aren't able to determine the "item" and leave the imports. Isn't there a third "leave the import" case where someone does one section that is static and a second section that is dynamic? Like the following.
<MenuTrigger>
<Button>Edit</Button>
<Menu>
<Section key={section.key} title="Static Menu Items">
<Item key="cut">Cut</Item>
<Item key="copy">Copy</Item>
</Section>
<Section key={section.key} title="Social Media Sites">
{items}
</Section
</Menu>
</MenuTrigger>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just tried this locally, and it kept the Item import. Are you seeing something different?
Before:
import {Menu, Section, Item, MenuTrigger, Button} from '@adobe/react-spectrum';
let items = [
{key: 'facebook', name: 'Facebook'},
{key: 'twitter', name: 'Twitter'},
{key: 'instagram', name: 'Instagram'},
].map(item => <Item key={item.key}>{item.name}</Item>);
<div>
<MenuTrigger>
<Button>Edit</Button>
<Menu>
<Section key={section.key} title="Static Menu Items">
<Item key="cut">Cut</Item>
<Item key="copy">Copy</Item>
</Section>
<Section key={section.key} title="Social Media Sites">
{items}
</Section>
</Menu>
</MenuTrigger>
</div>
After:
import { MenuSection, MenuItem, Menu, MenuTrigger, Button } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
let items = [
{key: 'facebook', name: 'Facebook'},
{key: 'twitter', name: 'Twitter'},
{key: 'instagram', name: 'Instagram'},
].map(item => // TODO(S2-upgrade): Couldn't automatically detect what type of collection component this is rendered in. You'll need to update this manually.
<Item key={item.key}>{item.name}</Item>);
<div>
<MenuTrigger>
<Button>Edit</Button>
<Menu>
<MenuSection id={section.key}><Header>Static Menu Items</Header>
<MenuItem id="cut">Cut</MenuItem>
<MenuItem id="copy">Copy</MenuItem>
</MenuSection>
<MenuSection id={section.key}><Header>Social Media Sites</Header>
{items}
</MenuSection>
</Menu>
</MenuTrigger>
</div>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just wanted that in a test. :)
…b.com/adobe/react-spectrum into codemod-remove-items-sections-imports
Previously we weren't removing Section or Item imports, because they may still be used by other components. Now we check if the import is still used, and removed it if not.
✅ Pull Request Checklist:
📝 Test Instructions:
🧢 Your Project: