-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(callout): reworked import portion of codemod
- Loading branch information
1 parent
dd8af3e
commit 78829a5
Showing
21 changed files
with
259 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/upgrade/transforms/__testfixtures__/refactor-to-callout.input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Typical imports | ||
import { unstable__StaticNotification as StaticNotification } from '@carbon/react'; | ||
import { unstable__StaticNotification } from '@carbon/react'; | ||
|
||
// If they used a custom name | ||
import { unstable__StaticNotification as SomeOtherName } from '@carbon/react'; | ||
|
||
// If they already renamed it Callout | ||
import { unstable__StaticNotification as Callout } from '@carbon/react'; | ||
|
||
// Local renames like this are unlikely but technically possible | ||
const LocallyRenamedStaticNotification = unstable__StaticNotification; | ||
|
||
// Component usages | ||
const App = () => { | ||
return ( | ||
<> | ||
<StaticNotification title="Test" /> | ||
<SomeOtherName title="Test" /> | ||
<Callout title="Test" /> | ||
<LocallyRenamedStaticNotification title="Test" /> | ||
</> | ||
); | ||
}; |
24 changes: 24 additions & 0 deletions
24
packages/upgrade/transforms/__testfixtures__/refactor-to-callout.output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Typical imports | ||
import { unstable__Callout as Callout } from '@carbon/react'; | ||
import { unstable__Callout } from '@carbon/react'; | ||
|
||
// If they used a custom name | ||
import { unstable__Callout as SomeOtherName } from '@carbon/react'; | ||
|
||
// If they already renamed it Callout | ||
import { unstable__Callout as Callout } from '@carbon/react'; | ||
|
||
// Local renames like this are unlikely but technically possible | ||
const LocallyRenamedStaticNotification = unstable__Callout; | ||
|
||
// Component usages | ||
const App = () => { | ||
return ( | ||
<> | ||
<Callout title="Test" /> | ||
<SomeOtherName title="Test" /> | ||
<Callout title="Test" /> | ||
<LocallyRenamedStaticNotification title="Test" /> | ||
</> | ||
); | ||
}; |
4 changes: 4 additions & 0 deletions
4
packages/upgrade/transforms/__testfixtures__/refactor-to-callout2.input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Existing usages should not be transformed | ||
import { unstable__Callout } from '@carbon/react'; | ||
import { unstable__Callout as Callout } from '@carbon/react'; | ||
import { unstable__Callout as SomeOtherOtherName } from '@carbon/react'; |
4 changes: 4 additions & 0 deletions
4
packages/upgrade/transforms/__testfixtures__/refactor-to-callout2.output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Existing usages should not be transformed | ||
import { unstable__Callout } from '@carbon/react'; | ||
import { unstable__Callout as Callout } from '@carbon/react'; | ||
import { unstable__Callout as SomeOtherOtherName } from '@carbon/react'; |
5 changes: 5 additions & 0 deletions
5
packages/upgrade/transforms/__testfixtures__/refactor-to-callout3.input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Do not transform potential naming collisions from local paths | ||
import { unstable__Callout } from './my/local/project'; | ||
import { unstable__Callout as Callout } from './my/local/project'; | ||
import { unstable_StaticNotification } from './my/local/project'; | ||
import { unstable_StaticNotification as StaticNotification } from './my/local/project'; |
5 changes: 5 additions & 0 deletions
5
packages/upgrade/transforms/__testfixtures__/refactor-to-callout3.output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Do not transform potential naming collisions from local paths | ||
import { unstable__Callout } from './my/local/project'; | ||
import { unstable__Callout as Callout } from './my/local/project'; | ||
import { unstable_StaticNotification } from './my/local/project'; | ||
import { unstable_StaticNotification as StaticNotification } from './my/local/project'; |
3 changes: 3 additions & 0 deletions
3
packages/upgrade/transforms/__testfixtures__/refactor-to-callout4.input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Do not transform potential naming collisions from local paths | ||
import { Callout } from '../my/local/project'; | ||
import { StaticNotification } from './my/local/project'; |
3 changes: 3 additions & 0 deletions
3
packages/upgrade/transforms/__testfixtures__/refactor-to-callout4.output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Do not transform potential naming collisions from local paths | ||
import { Callout } from '../my/local/project'; | ||
import { StaticNotification } from './my/local/project'; |
30 changes: 30 additions & 0 deletions
30
packages/upgrade/transforms/__testfixtures__/refactor-to-callout5.input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Fully qualified import paths from within es | ||
import { | ||
type StaticNotificationProps, | ||
StaticNotification, | ||
} from '@carbon/react/es/components/Notification'; | ||
|
||
// If the transform results in duplicate imports, they should be deduped | ||
import { unstable__StaticNotification } from '@carbon/react'; | ||
import { unstable__Callout } from '@carbon/react'; | ||
|
||
// Redefine the component with props to ensure type interface is handled | ||
const Notification: React.FC<StaticNotificationProps> = (props) => { | ||
return <StaticNotification {...props} />; | ||
}; | ||
|
||
// Local renames like this are unlikely but technically possible | ||
const LocallyRenamedStaticNotification = unstable__StaticNotification; | ||
const LocallyRenamedCallout = unstable__Callout; | ||
|
||
// Component usages | ||
const App = () => { | ||
return ( | ||
<> | ||
<StaticNotification title="Test" /> | ||
<LocallyRenamedCallout title="Test" /> | ||
<LocallyRenamedStaticNotification title="Test" /> | ||
<Notification title="test" /> | ||
</> | ||
); | ||
}; |
29 changes: 29 additions & 0 deletions
29
packages/upgrade/transforms/__testfixtures__/refactor-to-callout5.output.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Fully qualified import paths from within es | ||
import { | ||
type CalloutProps, | ||
Callout, | ||
} from '@carbon/react/es/components/Notification'; | ||
|
||
// If the transform results in duplicate imports, they should be deduped// note the de | ||
import { unstable__Callout } from '@carbon/react'; | ||
|
||
// Redefine the component with props to ensure type interface is handled | ||
const Notification: React.FC<CalloutProps> = (props) => { | ||
return <Callout {...props} />; | ||
}; | ||
|
||
// Local renames like this are unlikely but technically possible | ||
const LocallyRenamedStaticNotification = unstable__Callout; | ||
const LocallyRenamedCallout = unstable__Callout; | ||
|
||
// Component usages | ||
const App = () => { | ||
return ( | ||
<> | ||
<Callout title="Test" /> | ||
<LocallyRenamedCallout title="Test" /> | ||
<LocallyRenamedStaticNotification title="Test" /> | ||
<Notification title="test" /> | ||
</> | ||
); | ||
}; |
36 changes: 0 additions & 36 deletions
36
packages/upgrade/transforms/__testfixtures__/rename-staticnotification-to-callout.input.ts
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
packages/upgrade/transforms/__testfixtures__/rename-staticnotification-to-callout.output.ts
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
packages/upgrade/transforms/__tests__/refactor-to-callout.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Copyright IBM Corp. 2016, 2023 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const { defineTest } = require('jscodeshift/dist/testUtils'); | ||
|
||
defineTest(__dirname, 'refactor-to-callout'); | ||
defineTest(__dirname, 'refactor-to-callout', null, 'refactor-to-callout2'); | ||
defineTest(__dirname, 'refactor-to-callout', null, 'refactor-to-callout3'); | ||
defineTest(__dirname, 'refactor-to-callout', null, 'refactor-to-callout4'); | ||
defineTest(__dirname, 'refactor-to-callout', null, 'refactor-to-callout5'); |
12 changes: 0 additions & 12 deletions
12
packages/upgrade/transforms/__tests__/rename-staticnotification-to-callout.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.