From 6f745257022b0cac83e3dc4a574e10eedf13507a Mon Sep 17 00:00:00 2001 From: Katie McFaul Date: Mon, 19 Aug 2024 15:31:53 -0400 Subject: [PATCH 1/3] feat(Tile): add deprecated import update mod --- .../src/ruleCustomization.ts | 1 + .../v6/tileDeprecated/tile-deprecated.md | 17 ++++++++++++++ .../v6/tileDeprecated/tile-deprecated.test.ts | 22 +++++++++++++++++++ .../v6/tileDeprecated/tile-deprecated.ts | 20 +++++++++++++++++ .../v6/tileDeprecated/tileDeprecatedInput.tsx | 1 + .../tileDeprecated/tileDeprecatedOutput.tsx | 1 + 6 files changed, 62 insertions(+) create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/tileDeprecated/tile-deprecated.md create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/tileDeprecated/tile-deprecated.test.ts create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/tileDeprecated/tile-deprecated.ts create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/tileDeprecated/tileDeprecatedInput.tsx create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/tileDeprecated/tileDeprecatedOutput.tsx diff --git a/packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts b/packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts index 03873479f..cfae60a79 100644 --- a/packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts +++ b/packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts @@ -45,6 +45,7 @@ export const warningRules = [ "tabs-update-markup", "tabs-warn-children-type-changed", "Th-Td-warn-update-markup", + "tile-deprecated", "toolbarLabelGroupContent-updated-markup", "tooltip-warn-triggerRef-may-be-required", "treeView-warn-selectable-styling-modifier-removed", diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/tileDeprecated/tile-deprecated.md b/packages/eslint-plugin-pf-codemods/src/rules/v6/tileDeprecated/tile-deprecated.md new file mode 100644 index 000000000..2bbc6347e --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/tileDeprecated/tile-deprecated.md @@ -0,0 +1,17 @@ +### tile-deprecated [(#)](https://github.com/patternfly/patternfly-react/pull/10821) + +Tile has been deprecated. Running the fix flag will update your imports to our deprecated package, but we suggest using Card instead. + +#### Examples + +In: + +```jsx +%inputExample% +``` + +Out: + +```jsx +%outputExample% +``` diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/tileDeprecated/tile-deprecated.test.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/tileDeprecated/tile-deprecated.test.ts new file mode 100644 index 000000000..a0d2826fb --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/tileDeprecated/tile-deprecated.test.ts @@ -0,0 +1,22 @@ +const ruleTester = require('../../ruletester'); +import * as rule from './tile-deprecated'; + +ruleTester.run('tile-deprecated', rule, { + valid: [ + { + code: `import { Tile } from '@someOtherPackage';`, + }, + ], + invalid: [ + { + code: `import { Tile } from '@patternfly/react-core';`, + output: `import {\n\tTile\n} from '@patternfly/react-core/deprecated';`, + errors: [ + { + message: `Tile has been deprecated. Running the fix flag will update your imports to our deprecated package, but we suggest using Card instead.`, + type: 'ImportDeclaration', + }, + ], + }, + ], +}); \ No newline at end of file diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/tileDeprecated/tile-deprecated.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/tileDeprecated/tile-deprecated.ts new file mode 100644 index 000000000..281ab6780 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/tileDeprecated/tile-deprecated.ts @@ -0,0 +1,20 @@ +import { moveSpecifiers } from '../../helpers'; + +// https://github.com/patternfly/patternfly-react/pull/10821 + +const specifiersToMove = ['Tile']; + +const fromPackage = '@patternfly/react-core'; +const toPackage = '@patternfly/react-core/deprecated'; +const messageAfterImportNameChange = + 'been deprecated. Running the fix flag will update your imports to our deprecated package, but we suggest using Card instead.'; + +module.exports = { + meta: { fixable: 'code' }, + create: moveSpecifiers( + specifiersToMove, + fromPackage, + toPackage, + messageAfterImportNameChange + ), +}; \ No newline at end of file diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/tileDeprecated/tileDeprecatedInput.tsx b/packages/eslint-plugin-pf-codemods/src/rules/v6/tileDeprecated/tileDeprecatedInput.tsx new file mode 100644 index 000000000..dac62bf0b --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/tileDeprecated/tileDeprecatedInput.tsx @@ -0,0 +1 @@ +import { Tile } from "@patternfly/react-core"; diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/tileDeprecated/tileDeprecatedOutput.tsx b/packages/eslint-plugin-pf-codemods/src/rules/v6/tileDeprecated/tileDeprecatedOutput.tsx new file mode 100644 index 000000000..cbb5f0cc6 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/tileDeprecated/tileDeprecatedOutput.tsx @@ -0,0 +1 @@ +import { Tile } from "@patternfly/react-core/deprecated"; From 512c8801f233127e6ea81afc3f8f7c0fadbdd5d2 Mon Sep 17 00:00:00 2001 From: Katie McFaul Date: Wed, 21 Aug 2024 10:30:09 -0400 Subject: [PATCH 2/3] move tile rule to setupRules instead --- packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts b/packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts index cfae60a79..337d4789f 100644 --- a/packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts +++ b/packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts @@ -45,7 +45,6 @@ export const warningRules = [ "tabs-update-markup", "tabs-warn-children-type-changed", "Th-Td-warn-update-markup", - "tile-deprecated", "toolbarLabelGroupContent-updated-markup", "tooltip-warn-triggerRef-may-be-required", "treeView-warn-selectable-styling-modifier-removed", @@ -65,6 +64,7 @@ export const setupRules = [ "pageHeader-deprecated", "select-deprecated", "table-update-deprecatedPath", + "tile-deprecated", "wizard-update-deprecatedPath", ]; From 3b54b46003212c3728780451f6fcef1f79968c50 Mon Sep 17 00:00:00 2001 From: Katie McFaul Date: Tue, 24 Sep 2024 11:26:23 -0400 Subject: [PATCH 3/3] update md, add more tests --- .../v6/tileDeprecated/tile-deprecated.md | 4 +- .../v6/tileDeprecated/tile-deprecated.test.ts | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/tileDeprecated/tile-deprecated.md b/packages/eslint-plugin-pf-codemods/src/rules/v6/tileDeprecated/tile-deprecated.md index 2bbc6347e..f0cddd77a 100644 --- a/packages/eslint-plugin-pf-codemods/src/rules/v6/tileDeprecated/tile-deprecated.md +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/tileDeprecated/tile-deprecated.md @@ -1,6 +1,6 @@ -### tile-deprecated [(#)](https://github.com/patternfly/patternfly-react/pull/10821) +### tile-deprecated [(#10821)](https://github.com/patternfly/patternfly-react/pull/10821) -Tile has been deprecated. Running the fix flag will update your imports to our deprecated package, but we suggest using Card instead. +Tile has been deprecated. Running the fix flag will update your imports to our deprecated package, but we suggest using Card instead. There is a new Card example on our documentation showcasing how to set up a Card as a Tile. #### Examples diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/tileDeprecated/tile-deprecated.test.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/tileDeprecated/tile-deprecated.test.ts index a0d2826fb..c090dd63d 100644 --- a/packages/eslint-plugin-pf-codemods/src/rules/v6/tileDeprecated/tile-deprecated.test.ts +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/tileDeprecated/tile-deprecated.test.ts @@ -18,5 +18,45 @@ ruleTester.run('tile-deprecated', rule, { }, ], }, + { + code: `import { Tile as CustomTile } from '@patternfly/react-core';`, + output: `import {\n\tTile as CustomTile\n} from '@patternfly/react-core/deprecated';`, + errors: [ + { + message: `Tile has been deprecated. Running the fix flag will update your imports to our deprecated package, but we suggest using Card instead.`, + type: 'ImportDeclaration', + }, + ], + }, + { + code: `import { Tile } from '@patternfly/react-core/dist/esm/components/Tile/index.js';`, + output: `import {\n\tTile\n} from '@patternfly/react-core/dist/esm/deprecated/components/Tile/index.js';`, + errors: [ + { + message: `Tile has been deprecated. Running the fix flag will update your imports to our deprecated package, but we suggest using Card instead.`, + type: 'ImportDeclaration', + }, + ], + }, + { + code: `import { Tile } from '@patternfly/react-core/dist/js/components/Tile/index.js';`, + output: `import {\n\tTile\n} from '@patternfly/react-core/deprecated';`, + errors: [ + { + message: `Tile has been deprecated. Running the fix flag will update your imports to our deprecated package, but we suggest using Card instead.`, + type: 'ImportDeclaration', + }, + ], + }, + { + code: `import { Tile } from '@patternfly/react-core/dist/dynamic/components/Tile/index.js';`, + output: `import {\n\tTile\n} from '@patternfly/react-core/deprecated';`, + errors: [ + { + message: `Tile has been deprecated. Running the fix flag will update your imports to our deprecated package, but we suggest using Card instead.`, + type: 'ImportDeclaration', + }, + ], + }, ], }); \ No newline at end of file