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(PageSection): updated logic to account for variant enum #657

Merged
merged 2 commits into from
Jun 13, 2024

Conversation

thatblindgeye
Copy link
Collaborator

Closes #633


if (!attribute || !attribute.value) {
if (variantProp.value.type !== "Literal" && !hasPatternFlyEnum) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also check for Literal inside JSXExpressionContainer, like variant={"dark"}

Suggested change
if (variantProp.value.type !== "Literal" && !hasPatternFlyEnum) {
const variantValueIsLiteral =
variantProp.value.type === "Literal" ||
(variantProp.value.type === "JSXExpressionContainer" &&
variantProp.value.expression.type === "Literal");
if (!variantValueIsLiteral && !hasPatternFlyEnum) {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always forgetting this one 😆

Comment on lines 56 to 58
fix(fixer: {
replaceText: (arg0: any, arg1: string) => any;
}) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this custom type, as the correct type is derived from context: Rule.RuleContext

Suggested change
fix(fixer: {
replaceText: (arg0: any, arg1: string) => any;
}) {
fix(fixer) {

const hasValidValue = variantValue.property
? validValues.includes(variantValue.property.name)
: validValues.includes(variantValue);
console.log(hasValidValue);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: forgotten console.log

Suggested change
console.log(hasValidValue);

import { Rule } from "eslint";
import { JSXOpeningElement, JSXAttribute, Literal } from "estree-jsx";
import { isJsxAttribute } from "typescript";
import { JSXOpeningElement, JSXAttribute } from "estree-jsx";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: unused import

Suggested change
import { JSXOpeningElement, JSXAttribute } from "estree-jsx";
import { JSXOpeningElement } from "estree-jsx";

@@ -27,5 +36,95 @@ ruleTester.run("pageSection-update-variant-values", rule, {
},
],
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add test for the variant={"dark"}?

Suggested change
},
},
{
code: `import { PageSection } from '@patternfly/react-core'; <PageSection variant={"dark"} />`,
output: `import { PageSection } from '@patternfly/react-core'; <PageSection />`,
errors: [
{
message: `The \`variant\` prop for PageSection now only accepts a value of "default" or "secondary". Running the fix for this rule will remove the prop so it uses the default value of "default".`,
type: "JSXOpeningElement",
},
],
},

Copy link
Contributor

@adamviktora adamviktora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@adamviktora adamviktora merged commit 28cc392 into patternfly:main Jun 13, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PageSection - PageSectionVariants enum isn't picked up by the PageSection variant prop codemod
3 participants