-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(codemods): Button and ButtonLink have isSymmetrical prop instead…
… of isSquare #DS-1484
- Loading branch information
Showing
9 changed files
with
232 additions
and
0 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
24 changes: 24 additions & 0 deletions
24
packages/codemods/src/transforms/v3/web-react/__testfixtures__/button-prop-name.input.tsx
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 @@ | ||
import React from 'react'; | ||
// @ts-ignore: No declaration -- The library is not installed; we don't need to install it for fixtures. | ||
import { Button } from '@lmc-eu/spirit-web-react/src'; | ||
|
||
export const MyComponent = () => ( | ||
<> | ||
<Button color="primary" isSquare> | ||
Click me | ||
</Button> | ||
<Button color="primary" elementType="div" isSquare> | ||
Click me | ||
</Button> | ||
<Button color="primary" isDisabled isSquare> | ||
Click me | ||
</Button> | ||
<Button color="primary">Click me</Button> | ||
<Button color="primary" isDisabled isSquare={false}> | ||
Click me | ||
</Button> | ||
<Button color="primary" isDisabled isSquare={true}> | ||
Click me | ||
</Button> | ||
</> | ||
); |
24 changes: 24 additions & 0 deletions
24
packages/codemods/src/transforms/v3/web-react/__testfixtures__/button-prop-name.output.tsx
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 @@ | ||
import React from 'react'; | ||
// @ts-ignore: No declaration -- The library is not installed; we don't need to install it for fixtures. | ||
import { Button } from '@lmc-eu/spirit-web-react/src'; | ||
|
||
export const MyComponent = () => ( | ||
<> | ||
<Button color="primary" isSymmetrical> | ||
Click me | ||
</Button> | ||
<Button color="primary" elementType="div" isSymmetrical> | ||
Click me | ||
</Button> | ||
<Button color="primary" isDisabled isSymmetrical> | ||
Click me | ||
</Button> | ||
<Button color="primary">Click me</Button> | ||
<Button color="primary" isDisabled isSymmetrical={false}> | ||
Click me | ||
</Button> | ||
<Button color="primary" isDisabled isSymmetrical={true}> | ||
Click me | ||
</Button> | ||
</> | ||
); |
24 changes: 24 additions & 0 deletions
24
...ages/codemods/src/transforms/v3/web-react/__testfixtures__/buttonLink-prop-name.input.tsx
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 @@ | ||
import React from 'react'; | ||
// @ts-ignore: No declaration -- The library is not installed; we don't need to install it for fixtures. | ||
import { ButtonLink } from '@lmc-eu/spirit-web-react/src'; | ||
|
||
export const MyComponent = () => ( | ||
<> | ||
<ButtonLink href="" color="primary" isSquare> | ||
Click me | ||
</ButtonLink> | ||
<ButtonLink color="primary" elementType="div" isSquare> | ||
Click me | ||
</ButtonLink> | ||
<ButtonLink color="primary" isDisabled isSquare> | ||
Click me | ||
</ButtonLink> | ||
<ButtonLink color="primary">Click me</ButtonLink> | ||
<ButtonLink color="primary" isDisabled isSquare={false}> | ||
Click me | ||
</ButtonLink> | ||
<ButtonLink color="primary" isDisabled isSquare={true}> | ||
Click me | ||
</ButtonLink> | ||
</> | ||
); |
24 changes: 24 additions & 0 deletions
24
...ges/codemods/src/transforms/v3/web-react/__testfixtures__/buttonLink-prop-name.output.tsx
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 @@ | ||
import React from 'react'; | ||
// @ts-ignore: No declaration -- The library is not installed; we don't need to install it for fixtures. | ||
import { ButtonLink } from '@lmc-eu/spirit-web-react/src'; | ||
|
||
export const MyComponent = () => ( | ||
<> | ||
<ButtonLink href="" color="primary" isSymmetrical> | ||
Click me | ||
</ButtonLink> | ||
<ButtonLink color="primary" elementType="div" isSymmetrical> | ||
Click me | ||
</ButtonLink> | ||
<ButtonLink color="primary" isDisabled isSymmetrical> | ||
Click me | ||
</ButtonLink> | ||
<ButtonLink color="primary">Click me</ButtonLink> | ||
<ButtonLink color="primary" isDisabled isSymmetrical={false}> | ||
Click me | ||
</ButtonLink> | ||
<ButtonLink color="primary" isDisabled isSymmetrical={true}> | ||
Click me | ||
</ButtonLink> | ||
</> | ||
); |
3 changes: 3 additions & 0 deletions
3
packages/codemods/src/transforms/v3/web-react/__tests__/button-prop-name.test.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,3 @@ | ||
import { testTransform } from '../../../../../tests/testUtils'; | ||
|
||
testTransform(__dirname, 'button-prop-name'); |
3 changes: 3 additions & 0 deletions
3
packages/codemods/src/transforms/v3/web-react/__tests__/buttonLink-prop-name.test.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,3 @@ | ||
import { testTransform } from '../../../../../tests/testUtils'; | ||
|
||
testTransform(__dirname, 'buttonLink-prop-name'); |
50 changes: 50 additions & 0 deletions
50
packages/codemods/src/transforms/v3/web-react/button-prop-name.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,50 @@ | ||
import { API, FileInfo } from 'jscodeshift'; | ||
|
||
const transform = (fileInfo: FileInfo, api: API) => { | ||
const j = api.jscodeshift; | ||
const root = j(fileInfo.source); | ||
|
||
// Find import statements for the specific module and Button specifier | ||
const importStatements = root.find(j.ImportDeclaration, { | ||
source: { | ||
value: (value: string) => /^@lmc-eu\/spirit-web-react(\/.*)?$/.test(value), | ||
}, | ||
}); | ||
|
||
// Check if the module is imported | ||
if (importStatements.length > 0) { | ||
const componentSpecifier = importStatements.find(j.ImportSpecifier, { | ||
imported: { | ||
type: 'Identifier', | ||
name: 'Button', | ||
}, | ||
}); | ||
|
||
// Check if Button specifier is present | ||
if (componentSpecifier.length > 0) { | ||
// Find Button components in the module | ||
const components = root.find(j.JSXOpeningElement, { | ||
name: { | ||
type: 'JSXIdentifier', | ||
name: 'Button', | ||
}, | ||
}); | ||
|
||
// Rename 'isSquare' attribute to 'isSymmetrical' | ||
components | ||
.find(j.JSXAttribute, { | ||
name: { | ||
type: 'JSXIdentifier', | ||
name: 'isSquare', | ||
}, | ||
}) | ||
.forEach((attributePath) => { | ||
attributePath.node.name.name = 'isSymmetrical'; | ||
}); | ||
} | ||
} | ||
|
||
return root.toSource(); | ||
}; | ||
|
||
export default transform; |
50 changes: 50 additions & 0 deletions
50
packages/codemods/src/transforms/v3/web-react/buttonLink-prop-name.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,50 @@ | ||
import { API, FileInfo } from 'jscodeshift'; | ||
|
||
const transform = (fileInfo: FileInfo, api: API) => { | ||
const j = api.jscodeshift; | ||
const root = j(fileInfo.source); | ||
|
||
// Find import statements for the specific module and ButtonLink specifier | ||
const importStatements = root.find(j.ImportDeclaration, { | ||
source: { | ||
value: (value: string) => /^@lmc-eu\/spirit-web-react(\/.*)?$/.test(value), | ||
}, | ||
}); | ||
|
||
// Check if the module is imported | ||
if (importStatements.length > 0) { | ||
const componentSpecifier = importStatements.find(j.ImportSpecifier, { | ||
imported: { | ||
type: 'Identifier', | ||
name: 'ButtonLink', | ||
}, | ||
}); | ||
|
||
// Check if ButtonLink specifier is present | ||
if (componentSpecifier.length > 0) { | ||
// Find ButtonLink components in the module | ||
const components = root.find(j.JSXOpeningElement, { | ||
name: { | ||
type: 'JSXIdentifier', | ||
name: 'ButtonLink', | ||
}, | ||
}); | ||
|
||
// Rename 'isSquare' attribute to 'isSymmetrical' | ||
components | ||
.find(j.JSXAttribute, { | ||
name: { | ||
type: 'JSXIdentifier', | ||
name: 'isSquare', | ||
}, | ||
}) | ||
.forEach((attributePath) => { | ||
attributePath.node.name.name = 'isSymmetrical'; | ||
}); | ||
} | ||
} | ||
|
||
return root.toSource(); | ||
}; | ||
|
||
export default transform; |