-
Notifications
You must be signed in to change notification settings - Fork 20
feat/841: add optional codemod and flag for enabling animations #843
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...es/eslint-plugin-pf-codemods/src/rules/v6/enableAnimations/enable-animations.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| ### enable-animations | ||
|
|
||
| This rule adds the `hasAnimations` prop to PatternFly components that support animations. This is an optional enhancement that enables smoother transitions and animations in your UI components. | ||
|
|
||
| The following components will have `hasAnimations` added: | ||
| - AlertGroup | ||
| - DualListSelector | ||
| - FormFieldGroupExpandable | ||
| - SearchInput | ||
| - TreeView | ||
| - Table (from @patternfly/react-table) | ||
|
|
||
| This rule can only run using the `--only enable-animations` option. | ||
|
|
||
| #### Examples | ||
|
|
||
| In: | ||
|
|
||
| ```jsx | ||
| import { AlertGroup, TreeView } from '@patternfly/react-core'; | ||
| import { Table } from '@patternfly/react-table'; | ||
|
|
||
| export const Example = () => ( | ||
| <> | ||
| <AlertGroup isLiveRegion> | ||
| {/* alerts */} | ||
| </AlertGroup> | ||
| <TreeView /> | ||
| <Table /> | ||
| </> | ||
| ); | ||
| ``` | ||
|
|
||
| Out: | ||
|
|
||
| ```jsx | ||
| import { AlertGroup, TreeView } from '@patternfly/react-core'; | ||
| import { Table } from '@patternfly/react-table'; | ||
|
|
||
| export const Example = () => ( | ||
| <> | ||
| <AlertGroup hasAnimations isLiveRegion> | ||
| {/* alerts */} | ||
| </AlertGroup> | ||
| <TreeView hasAnimations /> | ||
| <Table hasAnimations /> | ||
| </> | ||
| ); | ||
| ``` | ||
152 changes: 152 additions & 0 deletions
152
packages/eslint-plugin-pf-codemods/src/rules/v6/enableAnimations/enable-animations.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| const ruleTester = require("../../ruletester"); | ||
| import * as rule from "./enable-animations"; | ||
|
|
||
| ruleTester.run("enable-animations", rule, { | ||
| valid: [ | ||
| // No imports, should not trigger | ||
| { | ||
| code: `<AlertGroup />`, | ||
| }, | ||
| // Already has hasAnimations prop | ||
| { | ||
| code: `import { AlertGroup } from '@patternfly/react-core'; <AlertGroup hasAnimations />`, | ||
| }, | ||
| // Already has hasAnimations with value | ||
| { | ||
| code: `import { AlertGroup } from '@patternfly/react-core'; <AlertGroup hasAnimations={true} />`, | ||
| }, | ||
| // Table already has hasAnimations | ||
| { | ||
| code: `import { Table } from '@patternfly/react-table'; <Table hasAnimations />`, | ||
| }, | ||
| // Non-target component should not be affected | ||
| { | ||
| code: `import { Button } from '@patternfly/react-core'; <Button />`, | ||
| }, | ||
| ], | ||
| invalid: [ | ||
| // AlertGroup without hasAnimations | ||
| { | ||
| code: `import { AlertGroup } from '@patternfly/react-core'; <AlertGroup />`, | ||
| output: `import { AlertGroup } from '@patternfly/react-core'; <AlertGroup hasAnimations />`, | ||
| errors: [ | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement", | ||
| }, | ||
| ], | ||
| }, | ||
| // DualListSelector without hasAnimations | ||
| { | ||
| code: `import { DualListSelector } from '@patternfly/react-core'; <DualListSelector />`, | ||
| output: `import { DualListSelector } from '@patternfly/react-core'; <DualListSelector hasAnimations />`, | ||
| errors: [ | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement", | ||
| }, | ||
| ], | ||
| }, | ||
| // TreeView without hasAnimations | ||
| { | ||
| code: `import { TreeView } from '@patternfly/react-core'; <TreeView />`, | ||
| output: `import { TreeView } from '@patternfly/react-core'; <TreeView hasAnimations />`, | ||
| errors: [ | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement", | ||
| }, | ||
| ], | ||
| }, | ||
| // SearchInput without hasAnimations | ||
| { | ||
| code: `import { SearchInput } from '@patternfly/react-core'; <SearchInput />`, | ||
| output: `import { SearchInput } from '@patternfly/react-core'; <SearchInput hasAnimations />`, | ||
| errors: [ | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement", | ||
| }, | ||
| ], | ||
| }, | ||
| // FormFieldGroupExpandable without hasAnimations | ||
| { | ||
| code: `import { FormFieldGroupExpandable } from '@patternfly/react-core'; <FormFieldGroupExpandable />`, | ||
| output: `import { FormFieldGroupExpandable } from '@patternfly/react-core'; <FormFieldGroupExpandable hasAnimations />`, | ||
| errors: [ | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement", | ||
| }, | ||
| ], | ||
| }, | ||
| // Table from react-table without hasAnimations | ||
| { | ||
| code: `import { Table } from '@patternfly/react-table'; <Table />`, | ||
| output: `import { Table } from '@patternfly/react-table'; <Table hasAnimations />`, | ||
| errors: [ | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement", | ||
| }, | ||
| ], | ||
| }, | ||
| // Multiple components in one file | ||
| { | ||
| code: `import { AlertGroup, TreeView } from '@patternfly/react-core'; | ||
| <> | ||
| <AlertGroup /> | ||
| <TreeView /> | ||
| </>`, | ||
| output: `import { AlertGroup, TreeView } from '@patternfly/react-core'; | ||
| <> | ||
| <AlertGroup hasAnimations /> | ||
| <TreeView hasAnimations /> | ||
| </>`, | ||
| errors: [ | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement", | ||
| }, | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement", | ||
| }, | ||
| ], | ||
| }, | ||
| // Component with existing props | ||
| { | ||
| code: `import { AlertGroup } from '@patternfly/react-core'; <AlertGroup isLiveRegion />`, | ||
| output: `import { AlertGroup } from '@patternfly/react-core'; <AlertGroup hasAnimations isLiveRegion />`, | ||
| errors: [ | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement", | ||
| }, | ||
| ], | ||
| }, | ||
| // Self-closing and regular tags | ||
| { | ||
| code: `import { DualListSelector } from '@patternfly/react-core'; | ||
| <> | ||
| <DualListSelector /> | ||
| <DualListSelector></DualListSelector> | ||
| </>`, | ||
| output: `import { DualListSelector } from '@patternfly/react-core'; | ||
| <> | ||
| <DualListSelector hasAnimations /> | ||
| <DualListSelector hasAnimations></DualListSelector> | ||
| </>`, | ||
| errors: [ | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement", | ||
| }, | ||
| { | ||
| message: "Consider adding hasAnimations prop to enable component animations.", | ||
| type: "JSXOpeningElement", | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }); |
75 changes: 75 additions & 0 deletions
75
packages/eslint-plugin-pf-codemods/src/rules/v6/enableAnimations/enable-animations.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import { Rule } from "eslint"; | ||
| import { JSXOpeningElement } from "estree-jsx"; | ||
| import { getFromPackage, checkMatchingJSXOpeningElement } from "../../helpers"; | ||
|
|
||
| // Rule to add hasAnimations prop to components that support animations | ||
| module.exports = { | ||
| meta: { fixable: "code" }, | ||
| create: function (context: Rule.RuleContext) { | ||
| // Get imports from both react-core and react-table packages | ||
| const { imports: coreImports } = getFromPackage( | ||
| context, | ||
| "@patternfly/react-core" | ||
| ); | ||
| const { imports: tableImports } = getFromPackage( | ||
| context, | ||
| "@patternfly/react-table" | ||
| ); | ||
|
|
||
| // Components that support hasAnimations prop | ||
| const targetComponents = [ | ||
| "FormFieldGroupExpandable", | ||
| "DualListSelector", | ||
| "TreeView", | ||
| "AlertGroup", | ||
| "SearchInput" | ||
| ]; | ||
|
|
||
| // Table comes from react-table package | ||
| const tableComponents = ["Table"]; | ||
|
|
||
| // Filter imports to only include target components | ||
| const targetCoreImports = coreImports.filter((specifier) => | ||
| targetComponents.includes(specifier.imported.name) | ||
| ); | ||
|
|
||
| const targetTableImports = tableImports.filter((specifier) => | ||
| tableComponents.includes(specifier.imported.name) | ||
| ); | ||
|
|
||
| const allTargetImports = [...targetCoreImports, ...targetTableImports]; | ||
|
|
||
| const message = | ||
| "Consider adding hasAnimations prop to enable component animations."; | ||
|
|
||
| return allTargetImports.length === 0 | ||
| ? {} | ||
| : { | ||
| JSXOpeningElement(node: JSXOpeningElement) { | ||
| if (checkMatchingJSXOpeningElement(node, allTargetImports)) { | ||
| // Check if hasAnimations prop already exists | ||
| const hasAnimationsAttribute = node.attributes.find( | ||
| (attr) => | ||
| attr.type === "JSXAttribute" && | ||
| attr.name.type === "JSXIdentifier" && | ||
| attr.name.name === "hasAnimations" | ||
| ); | ||
|
|
||
| // Only add prop if it doesn't already exist | ||
| if (!hasAnimationsAttribute) { | ||
| context.report({ | ||
| node, | ||
| message, | ||
| fix(fixer) { | ||
| return fixer.insertTextAfter( | ||
| node.name, | ||
| " hasAnimations" | ||
| ); | ||
| }, | ||
| }); | ||
| } | ||
| } | ||
| }, | ||
| }; | ||
| }, | ||
| }; |
15 changes: 15 additions & 0 deletions
15
packages/eslint-plugin-pf-codemods/src/rules/v6/enableAnimations/enableAnimationsInput.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { AlertGroup, TreeView, DualListSelector, SearchInput, FormFieldGroupExpandable } from "@patternfly/react-core"; | ||
| import { Table } from "@patternfly/react-table"; | ||
|
|
||
| export const EnableAnimationsInput = () => ( | ||
| <> | ||
| <AlertGroup isLiveRegion> | ||
| {/* alerts */} | ||
| </AlertGroup> | ||
| <TreeView /> | ||
| <DualListSelector /> | ||
| <SearchInput /> | ||
| <FormFieldGroupExpandable /> | ||
| <Table /> | ||
| </> | ||
| ); |
15 changes: 15 additions & 0 deletions
15
packages/eslint-plugin-pf-codemods/src/rules/v6/enableAnimations/enableAnimationsOutput.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { AlertGroup, TreeView, DualListSelector, SearchInput, FormFieldGroupExpandable } from "@patternfly/react-core"; | ||
| import { Table } from "@patternfly/react-table"; | ||
|
|
||
| export const EnableAnimationsOutput = () => ( | ||
| <> | ||
| <AlertGroup hasAnimations isLiveRegion> | ||
| {/* alerts */} | ||
| </AlertGroup> | ||
| <TreeView hasAnimations /> | ||
| <DualListSelector hasAnimations /> | ||
| <SearchInput hasAnimations /> | ||
| <FormFieldGroupExpandable hasAnimations /> | ||
| <Table hasAnimations /> | ||
| </> | ||
| ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: if you put in
my readme builder will insert the content of the *Input and *Output tsx files into the compiled readme