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

chore(generators): made enhancements to generator files #719

Merged
merged 2 commits into from
Aug 6, 2024

Conversation

thatblindgeye
Copy link
Collaborator

@thatblindgeye thatblindgeye commented Jul 26, 2024

Closes #720

node.name.type === "JSXIdentifier" &&
accordionItemImport.local.name === node.name.name
) {
if (checkMatchingJSXOpeningElement(node, accordionItemImport)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Only updated the one file for now. I could update the rest of the files as part of this or we can do that as a followup at some other point, I don't mind either way

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm also good either way you want to go about it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need to refactor our existing codemods, since they are a "one time use" code and we probably won't copy the code from them in the future. So IMO updating the write-rule generator is sufficient.

Copy link
Collaborator

@wise-king-sullyman wise-king-sullyman left a comment

Choose a reason for hiding this comment

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

Love this, just one question/thought

node.name.type === "JSXIdentifier" &&
accordionItemImport.local.name === node.name.name
) {
if (checkMatchingJSXOpeningElement(node, accordionItemImport)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm also good either way you want to go about it.

@@ -2,6 +2,7 @@ export interface Answers {
componentName: string;
propName: string;
ruleName: string;
referenceRepo: string;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we maybe have this be optional, with it defaulting to pf-react since that is what most of our mods are for?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@adamviktora wdyt?

For context there was some discussion on Slack:

  • My intent was to have the enum sort of be the source of truth for any repo names we create codemods for, with that being the only thing we would have to update (optimistically at least; the prompt creates an array for the values of this enum). It would involve less manually typing an exact repo correctly/ensuring the repo name is exactly correct for the PR url we create for the files
  • Alternatively, the repo name prompt becomes a regular input that defaults to patternfly-react, but have the ability to input custom text if you want

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the enum as it is now. When it is on patternfly-react as default, it is just one enter press, same as for the regular input. And I don't think we will need to specify many more custom repos in the future. And if so, there will probably be more codemods for that repo, so that's why I think updating an enum once and then picking an option is easier than always having to write a repo name manually.

@@ -2,6 +2,7 @@ export interface Answers {
componentName: string;
propName: string;
ruleName: string;
referenceRepo: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the enum as it is now. When it is on patternfly-react as default, it is just one enter press, same as for the regular input. And I don't think we will need to specify many more custom repos in the future. And if so, there will probably be more codemods for that repo, so that's why I think updating an enum once and then picking an option is easier than always having to write a repo name manually.

node.name.type === "JSXIdentifier" &&
accordionItemImport.local.name === node.name.name
) {
if (checkMatchingJSXOpeningElement(node, accordionItemImport)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need to refactor our existing codemods, since they are a "one time use" code and we probably won't copy the code from them in the future. So IMO updating the write-rule generator is sufficient.

(attr) =>
attr.type === "JSXAttribute" && attr.name.name === "${propName}"
);
if (checkMatchingJSXOpeningElement(node, componentImports)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a question - do we want to also care about default imports? It was a concern in the react-component-groups repo, where I created the getImportSpecifiersLocalNames helper for that, which was using the getDefaultImportsFromPackage helper inside. But it is rather an exception and most of the rules will still be on the patternfly-react repo where we don't have the default imports. So I am ok with keeping the generic generator like this.

Copy link
Collaborator

@wise-king-sullyman wise-king-sullyman Jul 29, 2024

Choose a reason for hiding this comment

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

Yeah it isn't something we need in most cases, but is there any reason we wouldn't want to handle default imports by default though? 🤔

Doesn't have to be part of this PR though.

Copy link
Collaborator

@wise-king-sullyman wise-king-sullyman left a comment

Choose a reason for hiding this comment

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

🚀

@wise-king-sullyman wise-king-sullyman merged commit 4c7d9da into patternfly:main Aug 6, 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.

Add enhancements to generators for dynamic url and cleaning up generic rule code
3 participants