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

feat(componentGroups): rename InvalidObjectProps to MissingPageProps #799

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

adamviktora
Copy link
Contributor

Closes #786

Adds a helper to rename interface. I added the @typescript-eslint/utils package for that reason to type the given typescript Nodes. However it does it not fit 100% with the current Rule.RuleContext we are using, so I had to do the node as unknown as Node casting.

In the future we might migrate to use @typescript-eslint/utils instead of estree-jsx entirely, but it would require basically updating every rule and helpers, so I don't know if it is worth it.

Comment on lines +10 to +12
function formatDefaultMessage(oldName: string, newName: string) {
return `${oldName} has been renamed to ${newName}.`;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not a blocker, but wondering if we should add a directory to helpers for these sort of default message functions. defaultMessages as the directory -> renameIdentifier.tsx as this helper for example. Or just yanking this out as its own individual helper to be reused elsewhere.

Comment on lines 54 to 55
!imports.some(
(specifier) => specifier.imported.name === node.imported.name
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we either rework/rename the checkSpecifierExists function in the checkMatchingImportDeclaration file to be used here, or create a matcher helper specifically for a specifier only?

Comment on lines 73 to 78
if (node.typeName.type === "Identifier") {
replaceIdentifier(node.typeName);
}
},
TSInterfaceHeritage(node: TSESTree.TSInterfaceHeritage) {
if (node.expression.type === "Identifier") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similar to above, maybe a matcher helper for these 2? I feel like rather than replaceIdentifier having a check to return early if an interface name isn't found in the imports, we should instead do what we're doing with the ImportSpecifier block and check first and only call the code to replace if a match is found.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated this to have a separate function to check whether the renaming should be done.

Do you see a reason in extracting that to a separate helper as well?

@@ -0,0 +1,18 @@
### component-groups-invalidObjectProps-rename-to-missingPageProps [(react-component-groups/#313)](https://github.com/patternfly/react-component-groups/pull/313)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This isn't a blocker for this PR, but sorta wondering if this should really be its own separate rule or included as part of the pre-existing one (with a rename maybe). Really the question is, "should there be a single rule dealing with anything InvalidObject rename related?"

Doing so would require a little refactoring both to the existing rule and the new helper here possibly, but also depends whether doing so would just bloat the existing rule too much. Having them separate may be more clear and understandable than trying to combine them, but curious what you think.

Copy link
Contributor Author

@adamviktora adamviktora Nov 12, 2024

Choose a reason for hiding this comment

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

"should there be a single rule dealing with anything InvalidObject rename related?"

I think ideally there should be just a single rule, but...

Doing so would require a little refactoring

I am afraid it could end up being "a lot of" refactoring, given that the current renameComponent helper already returns a function. But now that I am thinking about it, we could combine it and do something like:

create: (context: Rule.RuleContext) => {...renameComponent(args)(context), ...renameInterface(args)(context)}

But maybe it will not be that easy

Comment on lines 16 to 22
{
code: `import { InvalidObjectProps } from '@patternfly/react-core';`,
},
],
invalid: [
{
code: `import { InvalidObjectProps } from '@patternfly/react-component-groups';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe a valid test for importing something else from the correct package, and an invalid test that imports InvalidObjectProps and something else to show that only InvalidObjectProps gets touched/flagged?

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.

Component groups InvalidObject rename does not update InvalidObjectProps
2 participants