forked from patternfly/patternfly-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react-codemods): Added pf3-pf4 codemod (patternfly#468)
affects: @patternfly/react-codemods Added pf3-pf4 codemod for Buttons. The general framework should work for other components too. ISSUES CLOSED: patternfly#444
- Loading branch information
1 parent
23fd725
commit f43e285
Showing
10 changed files
with
482 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module.exports = { | ||
Button: { | ||
package: '@patternfly/react-core', | ||
props: { | ||
bsStyle: { | ||
name: 'variant', | ||
values: { | ||
primary: 'primary', | ||
link: 'link', | ||
danger: 'danger' | ||
}, | ||
defaultValue: 'secondary', | ||
fallbackValue: 'secondary' | ||
}, | ||
active: 'isActive', | ||
componentClass: 'component', | ||
disabled: 'isDisabled', | ||
block: 'isBlock', | ||
bsClass: { remove: true } | ||
}, | ||
unsupportedProps: ['bsSize'] | ||
} | ||
}; |
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
3 changes: 3 additions & 0 deletions
3
packages/react-codemods/transforms/__snapshots__/pf3-pf4.test.js.snap
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 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`throws error for components that are not supported 1`] = `"UnsupportedComponent is not a supported component"`; |
22 changes: 0 additions & 22 deletions
22
packages/react-codemods/transforms/patternfly-react-to-react-core.js
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
packages/react-codemods/transforms/patternfly-react-to-react-core.test.js
This file was deleted.
Oops, something went wrong.
119 changes: 119 additions & 0 deletions
119
packages/react-codemods/transforms/pf3-pf4.button.test.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,119 @@ | ||
import prettier from 'prettier'; | ||
import { defineInlineTest } from 'jscodeshift/dist/testUtils'; | ||
import transform from './pf3-pf4'; | ||
|
||
const prettierConfig = prettier.resolveConfig.sync(process.cwd()); | ||
const pretty = src => | ||
prettier.format(src, { parser: 'babylon', ...prettierConfig }); | ||
|
||
global.console.log = jest.fn(); | ||
|
||
defineInlineTest( | ||
transform, | ||
{}, | ||
` | ||
import { Button as PFButton } from 'patternfly-react'; | ||
const btn = <PFButton bsStyle='primary'>Button</PFButton>; | ||
`, | ||
pretty(` | ||
import { Button as PFButton } from '@patternfly/react-core'; | ||
const btn = <PFButton variant="primary">Button</PFButton>; | ||
`), | ||
'Supports import alias' | ||
); | ||
|
||
defineInlineTest( | ||
transform, | ||
{}, | ||
` | ||
import { Button } from 'patternfly-react'; | ||
const btn = <Button bsStyle='primary'>Button</Button>; | ||
`, | ||
pretty(` | ||
import { Button } from '@patternfly/react-core'; | ||
const btn = <Button variant="primary">Button</Button>; | ||
`), | ||
'Transforms bsStyle primary to variant primary' | ||
); | ||
|
||
defineInlineTest( | ||
transform, | ||
{}, | ||
` | ||
import { Button } from 'patternfly-react'; | ||
const btn = <Button block>Button</Button>; | ||
`, | ||
pretty(` | ||
import { Button } from '@patternfly/react-core'; | ||
const btn = <Button isBlock variant="secondary">Button</Button>; | ||
`), | ||
'Transforms block to isBlock' | ||
); | ||
|
||
defineInlineTest( | ||
transform, | ||
{}, | ||
` | ||
import { Button } from 'patternfly-react'; | ||
const btn = <Button disabled>Button</Button>; | ||
`, | ||
pretty(` | ||
import { Button } from '@patternfly/react-core'; | ||
const btn = <Button isDisabled variant="secondary">Button</Button>; | ||
`), | ||
'Transforms disabled to isDisabled' | ||
); | ||
|
||
defineInlineTest( | ||
transform, | ||
{}, | ||
` | ||
import { Button } from 'patternfly-react'; | ||
const btn = <Button active>Button</Button>; | ||
`, | ||
pretty(` | ||
import { Button } from '@patternfly/react-core'; | ||
const btn = <Button isActive variant="secondary">Button</Button>; | ||
`), | ||
'Transforms active to isActive' | ||
); | ||
|
||
defineInlineTest( | ||
transform, | ||
{}, | ||
` | ||
import { Button } from 'patternfly-react'; | ||
const btn = <Button componentClass="a">Button</Button>; | ||
`, | ||
pretty(` | ||
import { Button } from '@patternfly/react-core'; | ||
const btn = <Button component="a" variant="secondary">Button</Button>; | ||
`), | ||
'Transforms componentClass to component' | ||
); | ||
|
||
defineInlineTest( | ||
transform, | ||
{}, | ||
` | ||
import { Button } from 'patternfly-react'; | ||
const btn = <Button bsClass="btn">Button</Button>; | ||
`, | ||
pretty(` | ||
import { Button } from '@patternfly/react-core'; | ||
const btn = <Button variant="secondary">Button</Button>; | ||
`), | ||
'Removes bsClass prop' | ||
); | ||
|
||
defineInlineTest( | ||
transform, | ||
{}, | ||
` | ||
import { Button } from 'patternfly-react'; | ||
const btn = <Button bsSize="sm">Button</Button>; | ||
const supported = <Button>Button</Button>; | ||
`, | ||
'', | ||
'Ignores file for bsSize references' | ||
); |
Oops, something went wrong.