Skip to content

Commit

Permalink
feat(Card): Remove deprecated and unused props (#591)
Browse files Browse the repository at this point in the history
* feat(Card): Remove deprecated and unused props

* chore(Card): Bring md inline with other rules, unpretty tsx output file
  • Loading branch information
wise-king-sullyman authored Feb 27, 2024
1 parent d073617 commit 3d0cbb1
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 0 deletions.
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%
```

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,
],
});
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"),
},
},
}),
};
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={() => {}}
/>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Card } from "@patternfly/react-core";

export const CardRemoveVariousPropsInput = () => (
<Card





/>
);

0 comments on commit 3d0cbb1

Please sign in to comment.