-
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
224 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
21 changes: 21 additions & 0 deletions
21
...codemods/src/transforms/v3/web-react/__testfixtures__/button-isSquare-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,21 @@ | ||
// @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'; | ||
|
||
export const MyComponent = () => ( | ||
<> | ||
<Button isSquare>Click me</Button> | ||
<Button elementType="div" isSquare> | ||
Click me | ||
</Button> | ||
<Button isDisabled isSquare> | ||
Click me | ||
</Button> | ||
<Button color="primary">Click me</Button> | ||
<Button isDisabled isSquare={false}> | ||
Click me | ||
</Button> | ||
<Button isDisabled isSquare={true}> | ||
Click me | ||
</Button> | ||
</> | ||
); |
21 changes: 21 additions & 0 deletions
21
...odemods/src/transforms/v3/web-react/__testfixtures__/button-isSquare-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,21 @@ | ||
// @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'; | ||
|
||
export const MyComponent = () => ( | ||
<> | ||
<Button isSymmetrical>Click me</Button> | ||
<Button elementType="div" isSymmetrical> | ||
Click me | ||
</Button> | ||
<Button isDisabled isSymmetrical> | ||
Click me | ||
</Button> | ||
<Button color="primary">Click me</Button> | ||
<Button isDisabled isSymmetrical={false}> | ||
Click me | ||
</Button> | ||
<Button isDisabled isSymmetrical={true}> | ||
Click me | ||
</Button> | ||
</> | ||
); |
23 changes: 23 additions & 0 deletions
23
...mods/src/transforms/v3/web-react/__testfixtures__/buttonLink-isSquare-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,23 @@ | ||
// @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'; | ||
|
||
export const MyComponent = () => ( | ||
<> | ||
<ButtonLink href="" isSquare> | ||
Click me | ||
</ButtonLink> | ||
<ButtonLink elementType="div" isSquare> | ||
Click me | ||
</ButtonLink> | ||
<ButtonLink isDisabled isSquare> | ||
Click me | ||
</ButtonLink> | ||
<ButtonLink color="primary">Click me</ButtonLink> | ||
<ButtonLink isDisabled isSquare={false}> | ||
Click me | ||
</ButtonLink> | ||
<ButtonLink isDisabled isSquare={true}> | ||
Click me | ||
</ButtonLink> | ||
</> | ||
); |
23 changes: 23 additions & 0 deletions
23
...ods/src/transforms/v3/web-react/__testfixtures__/buttonLink-isSquare-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,23 @@ | ||
// @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'; | ||
|
||
export const MyComponent = () => ( | ||
<> | ||
<ButtonLink href="" isSymmetrical> | ||
Click me | ||
</ButtonLink> | ||
<ButtonLink elementType="div" isSymmetrical> | ||
Click me | ||
</ButtonLink> | ||
<ButtonLink isDisabled isSymmetrical> | ||
Click me | ||
</ButtonLink> | ||
<ButtonLink color="primary">Click me</ButtonLink> | ||
<ButtonLink isDisabled isSymmetrical={false}> | ||
Click me | ||
</ButtonLink> | ||
<ButtonLink isDisabled isSymmetrical={true}> | ||
Click me | ||
</ButtonLink> | ||
</> | ||
); |
3 changes: 3 additions & 0 deletions
3
packages/codemods/src/transforms/v3/web-react/__tests__/button-isSquare-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-isSquare-prop-name'); |
3 changes: 3 additions & 0 deletions
3
...ages/codemods/src/transforms/v3/web-react/__tests__/buttonLink-isSquare-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-isSquare-prop-name'); |
50 changes: 50 additions & 0 deletions
50
packages/codemods/src/transforms/v3/web-react/button-isSquare-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-isSquare-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; |