-
Notifications
You must be signed in to change notification settings - Fork 18
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
fix(PageSection): updated logic to account for variant enum #657
Conversation
|
||
if (!attribute || !attribute.value) { | ||
if (variantProp.value.type !== "Literal" && !hasPatternFlyEnum) { |
There was a problem hiding this comment.
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"}
if (variantProp.value.type !== "Literal" && !hasPatternFlyEnum) { | |
const variantValueIsLiteral = | |
variantProp.value.type === "Literal" || | |
(variantProp.value.type === "JSXExpressionContainer" && | |
variantProp.value.expression.type === "Literal"); | |
if (!variantValueIsLiteral && !hasPatternFlyEnum) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always forgetting this one 😆
fix(fixer: { | ||
replaceText: (arg0: any, arg1: string) => any; | ||
}) { |
There was a problem hiding this comment.
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
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: forgotten console.log
console.log(hasValidValue); |
import { Rule } from "eslint"; | ||
import { JSXOpeningElement, JSXAttribute, Literal } from "estree-jsx"; | ||
import { isJsxAttribute } from "typescript"; | ||
import { JSXOpeningElement, JSXAttribute } from "estree-jsx"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: unused import
import { JSXOpeningElement, JSXAttribute } from "estree-jsx"; | |
import { JSXOpeningElement } from "estree-jsx"; |
@@ -27,5 +36,95 @@ ruleTester.run("pageSection-update-variant-values", rule, { | |||
}, | |||
], | |||
}, |
There was a problem hiding this comment.
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"}
?
}, | |
}, | |
{ | |
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", | |
}, | |
], | |
}, |
8d87126
to
1c817dc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
Closes #633