-
Notifications
You must be signed in to change notification settings - Fork 19
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: type getVariableValue helper #796
base: main
Are you sure you want to change the base?
Conversation
9710972
to
e9f8593
Compare
packages/eslint-plugin-pf-codemods/src/rules/helpers/JSXAttributes.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin-pf-codemods/src/rules/helpers/JSXAttributes.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin-pf-codemods/src/rules/helpers/JSXAttributes.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin-pf-codemods/src/rules/helpers/getEnumPropertyName.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin-pf-codemods/src/rules/helpers/getEnumPropertyName.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin-pf-codemods/src/rules/helpers/getEnumPropertyName.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin-pf-codemods/src/rules/helpers/propertyNameMatches.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin-pf-codemods/src/rules/helpers/propertyNameMatches.ts
Outdated
Show resolved
Hide resolved
@@ -54,19 +53,23 @@ module.exports = { | |||
const selectableActionsValue = getAttributeValue( | |||
context, | |||
selectableActionsProp.value | |||
); | |||
) as ObjectExpression["properties"]; |
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.
If we're having to cast the return values of getAttributeValue
in mods now I feel like there's something not right going on.
I don't want to spam this comment out so echo this same thing for the below files where we're casting the return value.
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.
Here the casting is done because the actual selectableActions
prop on CardHeader
accepts only an object (CardHeaderSelectableActionsObject), so consumers shouldn't be able to pass anything else. I added a comment to make it clear.
The getAttributeValue
should ultimately get to the ObjectExpression, or return undefined (e.g. if it was an Identifier imported from another file) in which case we don't do the fix
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.
But yeah on many other places, the casting was done due to the lack of typing of the getAttributeValue
helper
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.
Great work on this so far! But I feel like for an issue focused on improving our typing we probably don't want to be adding a bunch of type casting if it can at all be avoided.
ccfc9bd
to
f553135
Compare
f553135
to
72f488f
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.
Great changes 🚀
I'm still not loving that we're having to make assertions about the return value pretty much everywhere we're using the helper now though. I'm not sure what can be done about that.... but I feel like there should be something.
Will do a little poking at this and probably come back with an approval after I can't find anything I like more.
Yeah, I don't love it either, but I think there is not a way of doing it without the type assertion. In most cases it is being used as a way of telling the rule what type will the prop of the PatternFly react component accept. So for example if we expect a variant value of an enum or string: Another approach we could use instead of casting could be that we pass the type we expect to get back as an argument to the In some cases the casting seems unnecessary ( |
Could we convert all of the return values into a standardized format (i.e. an object with a value field that holds the actual value and a type field that states what it is or something like that) so that the returned object is always consistent, then we can handle the return value in the mod based on the |
Closes #790, #630
I had to add some new helpers to simplify proper type checking.