Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(WizardStep): prevented omitting the WizardBody component #685

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### wizardStep-updated-body-typing [(#10637)](https://github.com/patternfly/patternfly-react/pull/10637)

The `body` prop on WizardStep no longer accepts a value of "null".

#### Examples

In:

```jsx
%inputExample%
```

Out:

```jsx
%outputExample%
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const ruleTester = require("../../ruletester");
import * as rule from "./wizardStep-updated-body-typing";

ruleTester.run("wizardStep-updated-body-typing", rule, {
valid: [
{
code: `<WizardStep body={null} />`,
},
{
code: `import { WizardStep } from '@patternfly/react-core'; <WizardStep body={{foo: "bar"}} />`,
},
{
code: `import { WizardStep } from '@patternfly/react-core'; <WizardStep body={undefined} />`,
},
],
invalid: [
{
code: `import { WizardStep } from '@patternfly/react-core'; <WizardStep body={null} />`,
output: `import { WizardStep } from '@patternfly/react-core'; <WizardStep />`,
errors: [
{
message: `The \`body\` prop on WizardStep no longer accepts a value of "null".`,
type: "JSXOpeningElement",
},
],
},
{
code: `import { WizardStep } from '@patternfly/react-core'; const bodyProp = null; <WizardStep body={bodyProp} />`,
output: `import { WizardStep } from '@patternfly/react-core'; const bodyProp = null; <WizardStep />`,
errors: [
{
message: `The \`body\` prop on WizardStep no longer accepts a value of "null".`,
type: "JSXOpeningElement",
},
],
},
{
code: `import { WizardStep } from '@patternfly/react-core/dist/esm/components/Wizard/index.js'; <WizardStep body={null} />`,
output: `import { WizardStep } from '@patternfly/react-core/dist/esm/components/Wizard/index.js'; <WizardStep />`,
errors: [
{
message: `The \`body\` prop on WizardStep no longer accepts a value of "null".`,
type: "JSXOpeningElement",
},
],
},
{
code: `import { WizardStep } from '@patternfly/react-core/dist/js/components/Wizard/index.js'; <WizardStep body={null} />`,
output: `import { WizardStep } from '@patternfly/react-core/dist/js/components/Wizard/index.js'; <WizardStep />`,
errors: [
{
message: `The \`body\` prop on WizardStep no longer accepts a value of "null".`,
type: "JSXOpeningElement",
},
],
},
{
code: `import { WizardStep } from '@patternfly/react-core/dist/dynamic/components/Wizard/index.js'; <WizardStep body={null} />`,
output: `import { WizardStep } from '@patternfly/react-core/dist/dynamic/components/Wizard/index.js'; <WizardStep />`,
errors: [
{
message: `The \`body\` prop on WizardStep no longer accepts a value of "null".`,
type: "JSXOpeningElement",
},
],
},
],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Rule } from "eslint";
import { JSXOpeningElement } from "estree-jsx";
import { getFromPackage, getAttribute, getAttributeValue } from "../../helpers";

// https://github.com/patternfly/patternfly-react/pull/10637
module.exports = {
meta: { fixable: "code" },
create: function (context: Rule.RuleContext) {
const { imports } = getFromPackage(context, "@patternfly/react-core");

const wizardStepImport = imports.find(
(specifier) => specifier.imported.name === "WizardStep"
);

return !wizardStepImport
? {}
: {
JSXOpeningElement(node: JSXOpeningElement) {
if (
node.name.type === "JSXIdentifier" &&
wizardStepImport.local.name === node.name.name
) {
const bodyProp = getAttribute(node, "body");
if (!bodyProp) {
return;
}
const bodyValue = getAttributeValue(context, bodyProp.value);

if (bodyValue === null) {
context.report({
node,
message: `The \`body\` prop on WizardStep no longer accepts a value of "null".`,
fix(fixer) {
return fixer.replaceText(bodyProp, "");
},
});
}
}
},
};
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { WizardStep } from "@patternfly/react-core";

export const WizardStepUpdatedBodyTypingInput = () => (
<WizardStep body={null} />
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { WizardStep } from "@patternfly/react-core";

export const WizardStepUpdatedBodyTypingInput = () => (
<WizardStep />
);
Loading