-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Card): Remove deprecated and unused props (#591)
* feat(Card): Remove deprecated and unused props * chore(Card): Bring md inline with other rules, unpretty tsx output file
- Loading branch information
1 parent
d073617
commit 3d0cbb1
Showing
5 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...in-pf-codemods/src/rules/v6/cardRemoveVariousProps/card-remove-various-props.md
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,25 @@ | ||
### card-remove-various-props [(#10056)](https://github.com/patternfly/patternfly-react/pull/10056) | ||
|
||
The following props have been removed from Card: | ||
- isSelectableRaised | ||
- isDisabledRaised | ||
- hasSelectableInput | ||
- selectableInputAriaLabel | ||
- onSelectableInputChange | ||
- isFlat | ||
- isRounded | ||
|
||
#### Examples | ||
|
||
In: | ||
|
||
```jsx | ||
%inputExample% | ||
``` | ||
|
||
Out: | ||
|
||
```jsx | ||
%outputExample% | ||
``` | ||
|
77 changes: 77 additions & 0 deletions
77
...-plugin-pf-codemods/src/rules/v6/cardRemoveVariousProps/card-remove-various-props.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,77 @@ | ||
const ruleTester = require("../../ruletester"); | ||
import * as rule from "./card-remove-various-props"; | ||
|
||
interface InvalidTest { | ||
code: string; | ||
output: string; | ||
errors: { message: string }[]; | ||
} | ||
|
||
const removedBooleanProps = [ | ||
"isSelectableRaised", | ||
"isDisabledRaised", | ||
"hasSelectableInput", | ||
"isFlat", | ||
"isRounded", | ||
]; | ||
const removedStringProps = ["selectableInputAriaLabel"]; | ||
const removedFunctionProps = ["onSelectableInputChange"]; | ||
|
||
const removedBooleanPropTests = removedBooleanProps.map((prop) => ({ | ||
code: `import { Card } from '@patternfly/react-core'; <Card ${prop} />`, | ||
output: `import { Card } from '@patternfly/react-core'; <Card />`, | ||
errors: [{ message: `The ${prop} prop has been removed` }], | ||
})); | ||
|
||
const removedStringPropTests = removedStringProps.reduce((acc, prop) => { | ||
return [ | ||
...acc, | ||
{ | ||
code: `import { Card } from '@patternfly/react-core'; <Card ${prop}='foo bar' />`, | ||
output: `import { Card } from '@patternfly/react-core'; <Card />`, | ||
errors: [{ message: `The ${prop} prop has been removed` }], | ||
}, | ||
{ | ||
code: `import { Card } from '@patternfly/react-core'; const foo = "foo bar"; <Card ${prop}={foo} />`, | ||
output: `import { Card } from '@patternfly/react-core'; const foo = "foo bar"; <Card />`, | ||
errors: [{ message: `The ${prop} prop has been removed` }], | ||
}, | ||
]; | ||
}, [] as InvalidTest[]); | ||
|
||
const removedFunctionPropTests = removedFunctionProps.reduce((acc, prop) => { | ||
return [ | ||
...acc, | ||
{ | ||
code: `import { Card } from '@patternfly/react-core'; <Card ${prop}={() => {}} />`, | ||
output: `import { Card } from '@patternfly/react-core'; <Card />`, | ||
errors: [{ message: `The ${prop} prop has been removed` }], | ||
}, | ||
{ | ||
code: `import { Card } from '@patternfly/react-core'; const foo = () => {}; <Card ${prop}={foo} />`, | ||
output: `import { Card } from '@patternfly/react-core'; const foo = () => {}; <Card />`, | ||
errors: [{ message: `The ${prop} prop has been removed` }], | ||
}, | ||
{ | ||
code: `import { Card } from '@patternfly/react-core'; function foo() {}; <Card ${prop}={foo} />`, | ||
output: `import { Card } from '@patternfly/react-core'; function foo() {}; <Card />`, | ||
errors: [{ message: `The ${prop} prop has been removed` }], | ||
}, | ||
]; | ||
}, [] as InvalidTest[]); | ||
|
||
ruleTester.run("card-remove-various-props", rule, { | ||
valid: [ | ||
{ | ||
code: `<Card isSelectableRaised isDisabledRaised hasSelectableInput selectableInputAriaLabel='foo bar' onSelectableInputChange={() => {}} isFlat isRounded />`, | ||
}, | ||
{ | ||
code: `import { Card } from '@patternfly/react-core'; <Card someOtherProp />`, | ||
}, | ||
], | ||
invalid: [ | ||
...removedBooleanPropTests, | ||
...removedStringPropTests, | ||
...removedFunctionPropTests, | ||
], | ||
}); |
40 changes: 40 additions & 0 deletions
40
...slint-plugin-pf-codemods/src/rules/v6/cardRemoveVariousProps/card-remove-various-props.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,40 @@ | ||
import { renameProps } from "../../helpers"; | ||
|
||
// https://github.com/patternfly/patternfly-react/pull/10056 | ||
const formatMessage = (propName: string) => | ||
`The ${propName} prop has been removed`; | ||
module.exports = { | ||
meta: { fixable: "code" }, | ||
create: renameProps({ | ||
Card: { | ||
isSelectableRaised: { | ||
newName: "", | ||
message: formatMessage("isSelectableRaised"), | ||
}, | ||
isDisabledRaised: { | ||
newName: "", | ||
message: formatMessage("isDisabledRaised"), | ||
}, | ||
hasSelectableInput: { | ||
newName: "", | ||
message: formatMessage("hasSelectableInput"), | ||
}, | ||
selectableInputAriaLabel: { | ||
newName: "", | ||
message: formatMessage("selectableInputAriaLabel"), | ||
}, | ||
onSelectableInputChange: { | ||
newName: "", | ||
message: formatMessage("onSelectableInputChange"), | ||
}, | ||
isFlat: { | ||
newName: "", | ||
message: formatMessage("isFlat"), | ||
}, | ||
isRounded: { | ||
newName: "", | ||
message: formatMessage("isRounded"), | ||
}, | ||
}, | ||
}), | ||
}; |
11 changes: 11 additions & 0 deletions
11
...nt-plugin-pf-codemods/src/rules/v6/cardRemoveVariousProps/cardRemoveVariousPropsInput.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,11 @@ | ||
import { Card } from "@patternfly/react-core"; | ||
|
||
export const CardRemoveVariousPropsInput = () => ( | ||
<Card | ||
isSelectableRaised | ||
isDisabledRaised | ||
hasSelectableInput | ||
selectableInputAriaLabel="aria label" | ||
onSelectableInputChange={() => {}} | ||
/> | ||
); |
11 changes: 11 additions & 0 deletions
11
...t-plugin-pf-codemods/src/rules/v6/cardRemoveVariousProps/cardRemoveVariousPropsOutput.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,11 @@ | ||
import { Card } from "@patternfly/react-core"; | ||
|
||
export const CardRemoveVariousPropsInput = () => ( | ||
<Card | ||
|
||
|
||
|
||
|
||
|
||
/> | ||
); |