Skip to content

Commit

Permalink
Codemod: remove Section and Items imports if not used elsewhere in fi…
Browse files Browse the repository at this point in the history
…le (adobe#6908)
  • Loading branch information
reidbarber authored Aug 22, 2024
1 parent c8e5ed4 commit dcf312b
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

exports[`Dynamic - no change 1`] = `
"import { MenuItem, ActionMenu } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
let actionMenuItems = [
{name: 'Cut'},
{name: 'Copy'},
Expand All @@ -19,7 +18,6 @@ let actionMenuItems = [

exports[`Static - no change 1`] = `
"import { MenuItem, ActionMenu } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
<div>
<ActionMenu>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

exports[`Comments out autoFocusCurrent 1`] = `
"import { Breadcrumb, Breadcrumbs } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
// TODO(S2-upgrade): S2 Breadcrumbs no longer includes a nav element by default. You can wrap the Breadcrumbs component in a nav element if needed.
// TODO(S2-upgrade): autoFocusCurrent has not been implemented yet.
Expand All @@ -15,7 +14,6 @@ import { Item } from '@adobe/react-spectrum';

exports[`Comments out isMultiline 1`] = `
"import { Breadcrumb, Breadcrumbs } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
// TODO(S2-upgrade): S2 Breadcrumbs no longer includes a nav element by default. You can wrap the Breadcrumbs component in a nav element if needed.
// TODO(S2-upgrade): isMultiline has not been implemented yet.
Expand All @@ -28,7 +26,6 @@ import { Item } from '@adobe/react-spectrum';

exports[`Comments out showRoot 1`] = `
"import { Breadcrumb, Breadcrumbs } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
// TODO(S2-upgrade): S2 Breadcrumbs no longer includes a nav element by default. You can wrap the Breadcrumbs component in a nav element if needed.
// TODO(S2-upgrade): showRoot has not been implemented yet.
Expand All @@ -43,7 +40,6 @@ import { Item } from '@adobe/react-spectrum';

exports[`Dynamic - Renames Item to Breadcrumb 1`] = `
"import { Breadcrumb, Breadcrumbs } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
let folders = [
{id: 1, label: 'Home'},
{id: 2, label: 'Trendy'},
Expand All @@ -59,7 +55,6 @@ let folders = [

exports[`Dynamic - Renames key to id 1`] = `
"import { Breadcrumb, Breadcrumbs } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
const items = [
{id: 1, name: 'News'},
{id: 2, name: 'Travel'},
Expand All @@ -84,7 +79,6 @@ const items = [

exports[`Leaves a comment if size prop contains "S" 1`] = `
"import { Breadcrumb, Breadcrumbs } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
// TODO(S2-upgrade): S2 Breadcrumbs no longer includes a nav element by default. You can wrap the Breadcrumbs component in a nav element if needed.
<Breadcrumbs // TODO(S2-upgrade): size="S" is no longer supported. You'll need to update this manually.
Expand All @@ -96,7 +90,6 @@ size={true ? 'M' : 'S'}>

exports[`Removes size="S" 1`] = `
"import { Breadcrumb, Breadcrumbs } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
// TODO(S2-upgrade): S2 Breadcrumbs no longer includes a nav element by default. You can wrap the Breadcrumbs component in a nav element if needed.
<Breadcrumbs>
Expand All @@ -107,7 +100,6 @@ import { Item } from '@adobe/react-spectrum';

exports[`Static - Renames Item to Breadcrumb and adds import 1`] = `
"import { Breadcrumb, Breadcrumbs } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
<div>
// TODO(S2-upgrade): S2 Breadcrumbs no longer includes a nav element by default. You can wrap the Breadcrumbs component in a nav element if needed.
Expand All @@ -121,7 +113,6 @@ import { Item } from '@adobe/react-spectrum';

exports[`Static - Renames key to id 1`] = `
"import { Breadcrumb, Breadcrumbs } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
let externalKey = 'travel';
<div>
// TODO(S2-upgrade): S2 Breadcrumbs no longer includes a nav element by default. You can wrap the Breadcrumbs component in a nav element if needed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

exports[`Dynamic - Renames Item to ComboBoxItem 1`] = `
"import { ComboBoxItem, ComboBox } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
let options = [
{id: 1, name: 'Aerospace'},
{id: 2, name: 'Mechanical'}
Expand All @@ -18,7 +17,6 @@ let options = [

exports[`Dynamic - Renames key to id 1`] = `
"import { ComboBoxItem, ComboBox } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
const items = [
{id: 1, name: 'News'},
{id: 2, name: 'Travel'},
Expand Down Expand Up @@ -46,7 +44,6 @@ const items = [

exports[`Removes isQuiet 1`] = `
"import { ComboBoxItem, ComboBox } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
let isQuiet = true;
let props = {isQuiet: true};
<div>
Expand Down Expand Up @@ -80,7 +77,6 @@ let props = {isQuiet: true};

exports[`Removes placeholder 1`] = `
"import { ComboBoxItem, ComboBox } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
let placeholder = 'is this actually removed?';
let props = {placeholder: 'is this actually removed?'};
<div>
Expand All @@ -106,7 +102,6 @@ let props = {placeholder: 'is this actually removed?'};

exports[`Static - Converts menuWidth to px value 1`] = `
"import { ComboBoxItem, ComboBox } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
let menuWidth = 'size-10';
let props = {menuWidth: 'size-10'};
<div>
Expand Down Expand Up @@ -142,7 +137,6 @@ let props = {menuWidth: 'size-10'};

exports[`Static - Renames Item to ComboBoxItem 1`] = `
"import { ComboBoxItem, ComboBox } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
<div>
<ComboBox label="Favorite Animal">
<ComboBoxItem>Red Panda</ComboBoxItem>
Expand All @@ -153,7 +147,6 @@ import { Item } from '@adobe/react-spectrum';

exports[`Static - Renames key to id 1`] = `
"import { ComboBoxItem, ComboBox } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
let externalKey = 'travel';
<div>
<ComboBox label="Favorite Animal">
Expand All @@ -165,7 +158,6 @@ let externalKey = 'travel';

exports[`changes validationState to isInvalid or nothing 1`] = `
"import { ComboBoxItem, ComboBox } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
let validationState = 'invalid';
let props = {validationState: 'invalid'};
<div>
Expand Down Expand Up @@ -199,7 +191,6 @@ let props = {validationState: 'invalid'};

exports[`changes validationState to isInvalid or nothing 2`] = `
"import { ComboBoxItem, ComboBox } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
let validationState = 'invalid';
let props = {validationState: 'invalid'};
<div>
Expand All @@ -226,7 +217,6 @@ let props = {validationState: 'invalid'};

exports[`handles sections 1`] = `
"import { ComboBoxSection, ComboBoxItem, ComboBox } from "@react-spectrum/s2";
import { Section, Item } from '@adobe/react-spectrum';
<ComboBox>
<ComboBoxSection><Header>Section title</Header>
<ComboBoxItem>Item one</ComboBoxItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,41 @@ import { StatusLight } from "@react-spectrum/s2";
</>"
`;

exports[`should remove unused Item/Section import even if name taken in different scope 1`] = `
"import { MenuSection, MenuItem, Menu } from "@react-spectrum/s2";
function foo() {
let Item = 'something else';
let Section = 'something else';
}
<div>
<Menu aria-label="Text">
<MenuSection><Header>Styles</Header>
<MenuItem id="bold">Bold</MenuItem>
<MenuItem id="underline">Underline</MenuItem>
</MenuSection>
</Menu>
</div>"
`;

exports[`should remove unused Item/Section import if aliased 1`] = `
"import { MenuSection, MenuItem, Menu } from "@react-spectrum/s2";
import {Section, Item} from 'elsewhere';
<div>
<Section>
<Item>Test</Item>
</Section>
<Menu aria-label="Text">
<MenuSection><Header>Styles</Header>
<MenuItem id="bold"></MenuItem>
<MenuItem id="underline">Underline</MenuItem>
</MenuSection>
</Menu>
</div>"
`;

exports[`should replace named imports 1`] = `
"import { Button } from "@react-spectrum/s2";
Expand All @@ -114,7 +149,6 @@ exports[`should replace named imports from individual packages 1`] = `

exports[`should use unique alias if newly imported component name is already in scope 1`] = `
"import { Tag as Tag1, TagGroup } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
const Tag = 'something else';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

exports[`Dynamic - Renames Item to MenuItem with Submenu, Section to MenuSection 1`] = `
"import { MenuItem, MenuSection, Menu, MenuTrigger, SubmenuTrigger, Button } from "@react-spectrum/s2";
import { Item, Section } from '@adobe/react-spectrum';
const items = [
{ id: 'copy', name: 'Copy' },
{ id: 'cut', name: 'Cut' },
Expand Down Expand Up @@ -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';
const items = [
{ key: 'copy', name: 'Copy' },
{ key: 'cut', name: 'Cut' },
Expand Down Expand Up @@ -164,8 +162,6 @@ exports[`Static - Renames Item to MenuItem, Section to MenuSection 1`] = `
Header,
Heading,
} from "@react-spectrum/s2";
import { Item, Section } from '@adobe/react-spectrum';
<div>
<MenuTrigger>
<Button>Edit</Button>
Expand Down Expand Up @@ -199,8 +195,6 @@ exports[`Static - Renames key to id 1`] = `
Header,
Heading,
} from "@react-spectrum/s2";
import { Item, Section } from '@adobe/react-spectrum';
<div>
<MenuTrigger>
<Button>Edit</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ exports[`Static - Renames Item to Breadcrumb and adds import 1`] = `
Heading,
} from "@react-spectrum/s2";
import { Item, Section } from '@adobe/react-spectrum';
<div>
// TODO(S2-upgrade): S2 Breadcrumbs no longer includes a nav element by default. You can wrap the Breadcrumbs component in a nav element if needed.
<Breadcrumbs>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

exports[`Dynamic - Renames Item to PickerItem 1`] = `
"import { PickerItem, Picker } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
let options = [
{id: 1, name: 'Chocolate'},
{id: 2, name: 'Vanilla'}
Expand All @@ -28,7 +27,6 @@ let options = [

exports[`Static - Converts menuWidth to px value 1`] = `
"import { PickerItem, Picker } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
let menuWidth = 'size-10';
let props = {menuWidth: 'size-10'};
<div>
Expand Down Expand Up @@ -64,7 +62,6 @@ let props = {menuWidth: 'size-10'};

exports[`Static - Removes isQuiet 1`] = `
"import { PickerItem, Picker } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
let isQuiet = true;
let props = {isQuiet: true};
<div>
Expand Down Expand Up @@ -94,7 +91,6 @@ let props = {isQuiet: true};

exports[`Static - Renames Item to PickerItem 1`] = `
"import { PickerItem, Picker } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
<div>
<Picker label="Ice Cream">
<PickerItem>Chocolate</PickerItem>
Expand All @@ -105,7 +101,6 @@ import { Item } from '@adobe/react-spectrum';

exports[`Static - Renames key to id 1`] = `
"import { PickerItem, Picker } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
<div>
<Picker label="Ice Cream">
<PickerItem id="chocolate">Chocolate</PickerItem>
Expand All @@ -116,7 +111,6 @@ import { Item } from '@adobe/react-spectrum';

exports[`changes validationState to isInvalid or nothing 1`] = `
"import { PickerItem, Picker } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
let validationState = 'invalid';
let props = {validationState: 'invalid'};
<div>
Expand Down Expand Up @@ -147,7 +141,6 @@ let props = {validationState: 'invalid'};

exports[`handles sections 1`] = `
"import { PickerSection, PickerItem, Picker } from "@react-spectrum/s2";
import { Section, Item } from '@adobe/react-spectrum';
<Picker>
<PickerSection><Header>Section title</Header>
<PickerItem>Item one</PickerItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ let items = [

exports[`Remove isEmphasized 1`] = `
"import { Tab, TabPanel, Tabs, TabList } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
let isEmphasized = true;
let props = {isEmphasized: true};
<div>
Expand Down Expand Up @@ -65,7 +64,6 @@ let props = {isEmphasized: true};

exports[`Remove isQuiet 1`] = `
"import { Tab, TabPanel, Tabs, TabList } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
let isQuiet = true;
let props = {isQuiet: true};
<div>
Expand Down Expand Up @@ -100,7 +98,6 @@ let props = {isQuiet: true};

exports[`Update to use new API 1`] = `
"import { Tab, TabPanel, Tabs, TabList } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
<Tabs aria-label="History of Ancient Rome"><TabList>
<Tab id="FoR">Founding of Rome</Tab>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

exports[`Dynamic - Renames Item to Tag 1`] = `
"import { Tag, TagGroup } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
const items = [
{id: 1, name: 'News'},
{id: 2, name: 'Travel'},
Expand All @@ -19,7 +18,6 @@ const items = [

exports[`Dynamic - Renames key to id 1`] = `
"import { Tag, TagGroup } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
const items = [
{id: 1, name: 'News'},
{id: 2, name: 'Travel'},
Expand All @@ -42,7 +40,6 @@ const items = [

exports[`Static - Renames Item to Tag 1`] = `
"import { Tag, TagGroup } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
<div>
<TagGroup aria-label="Static TagGroup items example">
Expand All @@ -56,7 +53,6 @@ import { Item } from '@adobe/react-spectrum';

exports[`Static - Renames key to id 1`] = `
"import { Tag, TagGroup } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
let externalKey = 'travel';
<div>
Expand All @@ -71,7 +67,6 @@ let externalKey = 'travel';

exports[`changes validationState to isInvalid or nothing 1`] = `
"import { Tag, TagGroup } from "@react-spectrum/s2";
import { Item } from '@adobe/react-spectrum';
let validationState = 'invalid';
let props = {validationState: 'invalid'};
Expand Down
Loading

0 comments on commit dcf312b

Please sign in to comment.