From e1c8083bfe1a158e14499885423fafe1f486c3d1 Mon Sep 17 00:00:00 2001 From: Eric Olkowski Date: Mon, 19 Feb 2024 15:55:49 -0500 Subject: [PATCH 1/4] feat(JumpLinks): warned about href and markup/type updates --- .../src/ruleCustomization.ts | 1 + .../jumpLinksItem-warn-prop-markup-updates.md | 3 ++ ...LinksItem-warn-prop-markup-updates.test.ts | 22 ++++++++++ .../jumpLinksItem-warn-prop-markup-updates.ts | 41 +++++++++++++++++++ ...umpLinksItemWarnPropMarkupUpdatesInput.tsx | 1 + ...mpLinksItemWarnPropMarkupUpdatesOutput.tsx | 1 + 6 files changed, 69 insertions(+) create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItem-warn-prop-markup-updates.md create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItem-warn-prop-markup-updates.test.ts create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItem-warn-prop-markup-updates.ts create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItemWarnPropMarkupUpdatesInput.tsx create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItemWarnPropMarkupUpdatesOutput.tsx diff --git a/packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts b/packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts index 3fd012fe5..bbce4a754 100644 --- a/packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts +++ b/packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts @@ -16,6 +16,7 @@ export const warningRules = [ "emptyState-warn-change-structure", "formControls-updated-markup", "horizontalSubnav-warn-ariaLabel", + "jumpLinksItem-warn-prop-markup-updates", "label-warn-truncated-default", "nav-warn-flyouts-now-inline", "overflowMenu-warn-updated-dropdownItem", diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItem-warn-prop-markup-updates.md b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItem-warn-prop-markup-updates.md new file mode 100644 index 000000000..34b805663 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItem-warn-prop-markup-updates.md @@ -0,0 +1,3 @@ +### jumpLinksItem-warn-href-required [(#10027)](https://github.com/patternfly/patternfly-react/pull/10027) + +The `href` prop on JumpLinksItem is now required. Additionally, the markup for JumpLinksItem and the typing of the `onClick` property has been updated as it now uses our Button component internally. diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItem-warn-prop-markup-updates.test.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItem-warn-prop-markup-updates.test.ts new file mode 100644 index 000000000..7e63f99c0 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItem-warn-prop-markup-updates.test.ts @@ -0,0 +1,22 @@ +const ruleTester = require("../../ruletester"); +import * as rule from "./jumpLinksItem-warn-prop-markup-updates"; + +ruleTester.run("jumpLinksItem-warn-prop-markup-updates", rule, { + valid: [ + { + code: `import { JumpLinksItem } from 'someOtherPackage';`, + }, + ], + invalid: [ + { + code: `import { JumpLinksItem } from '@patternfly/react-core';`, + output: `import { JumpLinksItem } from '@patternfly/react-core';`, + errors: [ + { + message: `The \`href\` prop on JumpLinksItem is now required. Additionally, the markup for JumpLinksItem and the typing of the \`onClick\` property has been updated as it now uses our Button component internally.`, + type: "ImportDeclaration", + }, + ], + }, + ], +}); diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItem-warn-prop-markup-updates.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItem-warn-prop-markup-updates.ts new file mode 100644 index 000000000..e4fd78449 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItem-warn-prop-markup-updates.ts @@ -0,0 +1,41 @@ +import { getFromPackage } from "../../helpers"; + +// https://github.com/patternfly/patternfly-react/pull/10027 +module.exports = { + meta: { fixable: "code" }, + create: function (context: { + report: (arg0: { + node: any; + message: string; + fix?(fixer: any): any; + }) => void; + }) { + const { imports } = getFromPackage(context, "@patternfly/react-core"); + + const jumpLinksItemImport = imports.find( + (specifier: { imported: { name: string } }) => + specifier.imported.name === "JumpLinksItem" + ); + + return !jumpLinksItemImport + ? {} + : { + ImportDeclaration(node: { + specifiers: { imported: { name: string } }[]; + }) { + if ( + node.specifiers.find( + (specifier: { imported: { name: string } }) => + specifier.imported.name === jumpLinksItemImport.imported.name + ) + ) { + context.report({ + node, + message: + "The `href` prop on JumpLinksItem is now required. Additionally, the markup for JumpLinksItem and the typing of the `onClick` property has been updated as it now uses our Button component internally.", + }); + } + }, + }; + }, +}; diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItemWarnPropMarkupUpdatesInput.tsx b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItemWarnPropMarkupUpdatesInput.tsx new file mode 100644 index 000000000..1982b083d --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItemWarnPropMarkupUpdatesInput.tsx @@ -0,0 +1 @@ +import { JumpLinksItem } from "@patternfly/react-core"; diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItemWarnPropMarkupUpdatesOutput.tsx b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItemWarnPropMarkupUpdatesOutput.tsx new file mode 100644 index 000000000..1982b083d --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItemWarnPropMarkupUpdatesOutput.tsx @@ -0,0 +1 @@ +import { JumpLinksItem } from "@patternfly/react-core"; From c5e7364b817fa102eebb9c6db65fa6a15e5199b6 Mon Sep 17 00:00:00 2001 From: Eric Olkowski Date: Mon, 26 Feb 2024 09:35:43 -0500 Subject: [PATCH 2/4] Separated href rule so it will flag as an error --- .../src/ruleCustomization.ts | 2 +- .../jumpLinksItem-href-required.md | 3 ++ .../jumpLinksItem-href-required.test.ts | 35 ++++++++++++++++ .../jumpLinksItem-href-required.ts | 39 ++++++++++++++++++ .../jumpLinksItemHrefRequiredInput.tsx | 8 ++++ .../jumpLinksItemHrefRequiredOutput.tsx | 8 ++++ .../jumpLinksItem-warn-markup-change.md | 3 ++ .../jumpLinksItem-warn-markup-change.test.ts | 25 +++++++++++ .../jumpLinksItem-warn-markup-change.ts | 36 ++++++++++++++++ .../jumpLinksItemWarnMarkupChangeInput.tsx} | 0 .../jumpLinksItemWarnMarkupChangeOutput.tsx} | 0 .../jumpLinksItem-warn-prop-markup-updates.md | 3 -- ...LinksItem-warn-prop-markup-updates.test.ts | 22 ---------- .../jumpLinksItem-warn-prop-markup-updates.ts | 41 ------------------- 14 files changed, 158 insertions(+), 67 deletions(-) create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemHrefRequired/jumpLinksItem-href-required.md create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemHrefRequired/jumpLinksItem-href-required.test.ts create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemHrefRequired/jumpLinksItem-href-required.ts create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemHrefRequired/jumpLinksItemHrefRequiredInput.tsx create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemHrefRequired/jumpLinksItemHrefRequiredOutput.tsx create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnMarkupChange/jumpLinksItem-warn-markup-change.md create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnMarkupChange/jumpLinksItem-warn-markup-change.test.ts create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnMarkupChange/jumpLinksItem-warn-markup-change.ts rename packages/eslint-plugin-pf-codemods/src/rules/v6/{jumpLinksItemWarnPropMarkupUpdates/jumpLinksItemWarnPropMarkupUpdatesInput.tsx => jumpLinksItemWarnMarkupChange/jumpLinksItemWarnMarkupChangeInput.tsx} (100%) rename packages/eslint-plugin-pf-codemods/src/rules/v6/{jumpLinksItemWarnPropMarkupUpdates/jumpLinksItemWarnPropMarkupUpdatesOutput.tsx => jumpLinksItemWarnMarkupChange/jumpLinksItemWarnMarkupChangeOutput.tsx} (100%) delete mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItem-warn-prop-markup-updates.md delete mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItem-warn-prop-markup-updates.test.ts delete mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItem-warn-prop-markup-updates.ts diff --git a/packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts b/packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts index bbce4a754..0174768ef 100644 --- a/packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts +++ b/packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts @@ -16,7 +16,7 @@ export const warningRules = [ "emptyState-warn-change-structure", "formControls-updated-markup", "horizontalSubnav-warn-ariaLabel", - "jumpLinksItem-warn-prop-markup-updates", + "jumpLinksItem-warn-markup-change", "label-warn-truncated-default", "nav-warn-flyouts-now-inline", "overflowMenu-warn-updated-dropdownItem", diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemHrefRequired/jumpLinksItem-href-required.md b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemHrefRequired/jumpLinksItem-href-required.md new file mode 100644 index 000000000..4f41bd6b6 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemHrefRequired/jumpLinksItem-href-required.md @@ -0,0 +1,3 @@ +### jumpLinksItem-href-required [(#10027)](https://github.com/patternfly/patternfly-react/pull/10027) + +The `href` prop on JumpLinksItem is now required. diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemHrefRequired/jumpLinksItem-href-required.test.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemHrefRequired/jumpLinksItem-href-required.test.ts new file mode 100644 index 000000000..3fa1456d4 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemHrefRequired/jumpLinksItem-href-required.test.ts @@ -0,0 +1,35 @@ +const ruleTester = require("../../ruletester"); +import * as rule from "./jumpLinksItem-href-required"; + +ruleTester.run("jumpLinksItem-href-required", rule, { + valid: [ + { + code: `import { JumpLinksItem } from 'someOtherPackage'; `, + }, + { + code: `import { JumpLinksItem } from '@patternfly/react-core'; `, + }, + ], + invalid: [ + { + code: `import { JumpLinksItem } from '@patternfly/react-core'; `, + output: `import { JumpLinksItem } from '@patternfly/react-core'; `, + errors: [ + { + message: `The \`href\` prop on JumpLinksItem is now required.`, + type: "JSXOpeningElement", + }, + ], + }, + { + code: `import { JumpLinksItem } from '@patternfly/react-core'; `, + output: `import { JumpLinksItem } from '@patternfly/react-core'; `, + errors: [ + { + message: `The \`href\` prop on JumpLinksItem is now required.`, + type: "JSXOpeningElement", + }, + ], + }, + ], +}); diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemHrefRequired/jumpLinksItem-href-required.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemHrefRequired/jumpLinksItem-href-required.ts new file mode 100644 index 000000000..d76b3bf4c --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemHrefRequired/jumpLinksItem-href-required.ts @@ -0,0 +1,39 @@ +import { getFromPackage } from "../../helpers"; +import { Rule } from "eslint"; +import { JSXOpeningElement, JSXAttribute } from "estree-jsx"; + +// https://github.com/patternfly/patternfly-react/pull/10027 +module.exports = { + meta: {}, + create: function (context: Rule.RuleContext) { + const { imports } = getFromPackage(context, "@patternfly/react-core"); + + const jumpLinksItemImport = imports.find( + (specifier) => specifier.imported.name === "JumpLinksItem" + ); + + return !jumpLinksItemImport + ? {} + : { + JSXOpeningElement(node: JSXOpeningElement) { + if ( + node.name.type === "JSXIdentifier" && + jumpLinksItemImport.local.name === node.name.name + ) { + const hrefAttribute = node.attributes.find( + (attribute) => + attribute.type === "JSXAttribute" && + attribute.name.name === "href" + ); + + if (!hrefAttribute || !(hrefAttribute as JSXAttribute).value) { + context.report({ + node, + message: "The `href` prop on JumpLinksItem is now required.", + }); + } + } + }, + }; + }, +}; diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemHrefRequired/jumpLinksItemHrefRequiredInput.tsx b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemHrefRequired/jumpLinksItemHrefRequiredInput.tsx new file mode 100644 index 000000000..1635e8073 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemHrefRequired/jumpLinksItemHrefRequiredInput.tsx @@ -0,0 +1,8 @@ +import { JumpLinksItem } from "@patternfly/react-core"; + +export const JumpLinksItemWarnMarkupChangeInput = () => ( + <> + + + +); diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemHrefRequired/jumpLinksItemHrefRequiredOutput.tsx b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemHrefRequired/jumpLinksItemHrefRequiredOutput.tsx new file mode 100644 index 000000000..1635e8073 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemHrefRequired/jumpLinksItemHrefRequiredOutput.tsx @@ -0,0 +1,8 @@ +import { JumpLinksItem } from "@patternfly/react-core"; + +export const JumpLinksItemWarnMarkupChangeInput = () => ( + <> + + + +); diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnMarkupChange/jumpLinksItem-warn-markup-change.md b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnMarkupChange/jumpLinksItem-warn-markup-change.md new file mode 100644 index 000000000..0b26b83e9 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnMarkupChange/jumpLinksItem-warn-markup-change.md @@ -0,0 +1,3 @@ +### jumpLinksItem-warn-markup-change [(#10027)](https://github.com/patternfly/patternfly-react/pull/10027) + +The markup for JumpLinksItem has changed, as it now uses our Button component internally. Additionally, the `onClick` prop type has been updated to just `React.MouseEvent` (previously `React.MouseEvent`). diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnMarkupChange/jumpLinksItem-warn-markup-change.test.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnMarkupChange/jumpLinksItem-warn-markup-change.test.ts new file mode 100644 index 000000000..59fa15e07 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnMarkupChange/jumpLinksItem-warn-markup-change.test.ts @@ -0,0 +1,25 @@ +const ruleTester = require("../../ruletester"); +import * as rule from "./jumpLinksItem-warn-markup-change"; + +ruleTester.run("jumpLinksItem-warn-markup-change", rule, { + valid: [ + { + code: ``, + }, + { + code: `import { JumpLinksItem } from '@someOtherPackage';`, + }, + ], + invalid: [ + { + code: `import { JumpLinksItem } from '@patternfly/react-core'; `, + output: `import { JumpLinksItem } from '@patternfly/react-core'; `, + errors: [ + { + message: `The markup for JumpLinksItem has changed, as it now uses our Button component internally. Additionally, the \`onClick\` prop type has been updated to just \`React.MouseEvent\` (previously \`React.MouseEvent\`).`, + type: "ImportDeclaration", + }, + ], + }, + ], +}); diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnMarkupChange/jumpLinksItem-warn-markup-change.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnMarkupChange/jumpLinksItem-warn-markup-change.ts new file mode 100644 index 000000000..70caa4646 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnMarkupChange/jumpLinksItem-warn-markup-change.ts @@ -0,0 +1,36 @@ +import { getFromPackage } from "../../helpers"; +import { Rule } from "eslint"; +import { ImportDeclaration, ImportSpecifier } from "estree-jsx"; + +// https://github.com/patternfly/patternfly-react/pull/10027 +module.exports = { + meta: {}, + create: function (context: Rule.RuleContext) { + const { imports } = getFromPackage(context, "@patternfly/react-core"); + + const jumpLinksItemImport = imports.find( + (specifier: { imported: { name: string } }) => + specifier.imported.name === "JumpLinksItem" + ); + + return !jumpLinksItemImport + ? {} + : { + ImportDeclaration(node: ImportDeclaration) { + if ( + node.specifiers.find( + (specifier) => + (specifier as ImportSpecifier)?.imported.name === + jumpLinksItemImport.imported.name + ) + ) { + context.report({ + node, + message: + "The markup for JumpLinksItem has changed, as it now uses our Button component internally. Additionally, the `onClick` prop type has been updated to just `React.MouseEvent` (previously `React.MouseEvent`).", + }); + } + }, + }; + }, +}; diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItemWarnPropMarkupUpdatesInput.tsx b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnMarkupChange/jumpLinksItemWarnMarkupChangeInput.tsx similarity index 100% rename from packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItemWarnPropMarkupUpdatesInput.tsx rename to packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnMarkupChange/jumpLinksItemWarnMarkupChangeInput.tsx diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItemWarnPropMarkupUpdatesOutput.tsx b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnMarkupChange/jumpLinksItemWarnMarkupChangeOutput.tsx similarity index 100% rename from packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItemWarnPropMarkupUpdatesOutput.tsx rename to packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnMarkupChange/jumpLinksItemWarnMarkupChangeOutput.tsx diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItem-warn-prop-markup-updates.md b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItem-warn-prop-markup-updates.md deleted file mode 100644 index 34b805663..000000000 --- a/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItem-warn-prop-markup-updates.md +++ /dev/null @@ -1,3 +0,0 @@ -### jumpLinksItem-warn-href-required [(#10027)](https://github.com/patternfly/patternfly-react/pull/10027) - -The `href` prop on JumpLinksItem is now required. Additionally, the markup for JumpLinksItem and the typing of the `onClick` property has been updated as it now uses our Button component internally. diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItem-warn-prop-markup-updates.test.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItem-warn-prop-markup-updates.test.ts deleted file mode 100644 index 7e63f99c0..000000000 --- a/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItem-warn-prop-markup-updates.test.ts +++ /dev/null @@ -1,22 +0,0 @@ -const ruleTester = require("../../ruletester"); -import * as rule from "./jumpLinksItem-warn-prop-markup-updates"; - -ruleTester.run("jumpLinksItem-warn-prop-markup-updates", rule, { - valid: [ - { - code: `import { JumpLinksItem } from 'someOtherPackage';`, - }, - ], - invalid: [ - { - code: `import { JumpLinksItem } from '@patternfly/react-core';`, - output: `import { JumpLinksItem } from '@patternfly/react-core';`, - errors: [ - { - message: `The \`href\` prop on JumpLinksItem is now required. Additionally, the markup for JumpLinksItem and the typing of the \`onClick\` property has been updated as it now uses our Button component internally.`, - type: "ImportDeclaration", - }, - ], - }, - ], -}); diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItem-warn-prop-markup-updates.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItem-warn-prop-markup-updates.ts deleted file mode 100644 index e4fd78449..000000000 --- a/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnPropMarkupUpdates/jumpLinksItem-warn-prop-markup-updates.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { getFromPackage } from "../../helpers"; - -// https://github.com/patternfly/patternfly-react/pull/10027 -module.exports = { - meta: { fixable: "code" }, - create: function (context: { - report: (arg0: { - node: any; - message: string; - fix?(fixer: any): any; - }) => void; - }) { - const { imports } = getFromPackage(context, "@patternfly/react-core"); - - const jumpLinksItemImport = imports.find( - (specifier: { imported: { name: string } }) => - specifier.imported.name === "JumpLinksItem" - ); - - return !jumpLinksItemImport - ? {} - : { - ImportDeclaration(node: { - specifiers: { imported: { name: string } }[]; - }) { - if ( - node.specifiers.find( - (specifier: { imported: { name: string } }) => - specifier.imported.name === jumpLinksItemImport.imported.name - ) - ) { - context.report({ - node, - message: - "The `href` prop on JumpLinksItem is now required. Additionally, the markup for JumpLinksItem and the typing of the `onClick` property has been updated as it now uses our Button component internally.", - }); - } - }, - }; - }, -}; From 49ef5b6a34b28eb6297702b84527f5aa19c4b0b3 Mon Sep 17 00:00:00 2001 From: Eric Olkowski Date: Mon, 26 Feb 2024 10:32:55 -0500 Subject: [PATCH 3/4] Added typing to PageSection rules --- .../pageSection-update-variant-values.ts | 38 +++++++++---------- ...pageSection-warn-variantClasses-applied.ts | 28 ++++++-------- 2 files changed, 30 insertions(+), 36 deletions(-) diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/pageSectionUpdateVariantValues/pageSection-update-variant-values.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/pageSectionUpdateVariantValues/pageSection-update-variant-values.ts index 661fc23d2..6a395a44d 100644 --- a/packages/eslint-plugin-pf-codemods/src/rules/v6/pageSectionUpdateVariantValues/pageSection-update-variant-values.ts +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/pageSectionUpdateVariantValues/pageSection-update-variant-values.ts @@ -1,39 +1,39 @@ import { getFromPackage } from "../../helpers"; +import { Rule } from "eslint"; +import { JSXOpeningElement, JSXAttribute, Literal } from "estree-jsx"; +import { isJsxAttribute } from "typescript"; // https://github.com/patternfly/patternfly-react/pull/9774 // https://github.com/patternfly/patternfly-react/pull/9848 module.exports = { meta: { fixable: "code" }, - create: function (context: { - report: (arg0: { - node: any; - message: string; - fix(fixer: any): any; - }) => void; - }) { + create: function (context: Rule.RuleContext) { const { imports } = getFromPackage(context, "@patternfly/react-core"); - const componentImports = imports.filter( - (specifier: { imported: { name: string } }) => - specifier.imported.name === "PageSection" + const pageSectionImport = imports.find( + (specifier) => specifier.imported.name === "PageSection" ); - return !componentImports.length + return !pageSectionImport ? {} : { - JSXOpeningElement(node: { name: { name: any }; attributes: any[] }) { + JSXOpeningElement(node: JSXOpeningElement) { if ( - componentImports - .map((imp: { local: { name: any } }) => imp.local.name) - .includes(node.name.name) + node.name.type === "JSXIdentifier" && + pageSectionImport.local.name === node.name.name ) { const attribute = node.attributes.find( - (attr: { name: { name: string } }) => - attr.name?.name === "variant" - ); + (attr) => + attr.type === "JSXAttribute" && attr.name.name === "variant" + ) as JSXAttribute | undefined; + + if (!attribute || !attribute.value) { + return; + } if ( - attribute && + attribute.value.type === "Literal" && + typeof attribute.value.value === "string" && !["default", "secondary"].includes(attribute.value.value) ) { context.report({ diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/pageSectionWarnVariantClassesApplied/pageSection-warn-variantClasses-applied.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/pageSectionWarnVariantClassesApplied/pageSection-warn-variantClasses-applied.ts index b8591086e..57f038f34 100644 --- a/packages/eslint-plugin-pf-codemods/src/rules/v6/pageSectionWarnVariantClassesApplied/pageSection-warn-variantClasses-applied.ts +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/pageSectionWarnVariantClassesApplied/pageSection-warn-variantClasses-applied.ts @@ -1,34 +1,28 @@ import { getFromPackage } from "../../helpers"; +import { Rule } from "eslint"; +import { JSXOpeningElement } from "estree-jsx"; // https://github.com/patternfly/patternfly-react/pull/9848 module.exports = { meta: {}, - create: function (context: { - report: (arg0: { - node: any; - message: string; - fix?(fixer: any): any; - }) => void; - }) { + create: function (context: Rule.RuleContext) { const { imports } = getFromPackage(context, "@patternfly/react-core"); - const componentImports = imports.filter( - (specifier: { imported: { name: string } }) => - specifier.imported.name === "PageSection" + const pageSectionImport = imports.find( + (specifier) => specifier.imported.name === "PageSection" ); - return !componentImports.length + return !pageSectionImport ? {} : { - JSXOpeningElement(node: { name: { name: any }; attributes: any[] }) { + JSXOpeningElement(node: JSXOpeningElement) { if ( - componentImports - .map((imp: { local: { name: any } }) => imp.local.name) - .includes(node.name.name) + node.name.type === "JSXIdentifier" && + pageSectionImport.local.name === node.name.name ) { const attribute = node.attributes.find( - (attr: { name: { name: string } }) => - attr.name?.name === "variant" + (attr) => + attr.type === "JSXAttribute" && attr.name.name === "variant" ); if (attribute) { context.report({ From c0c81113acb32d23e740eb33b892f94b4d8c8261 Mon Sep 17 00:00:00 2001 From: Eric Olkowski Date: Mon, 26 Feb 2024 10:46:57 -0500 Subject: [PATCH 4/4] Updated typing in markup warn rule --- .../jumpLinksItem-warn-markup-change.test.ts | 7 ++----- .../jumpLinksItem-warn-markup-change.ts | 7 +++---- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnMarkupChange/jumpLinksItem-warn-markup-change.test.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnMarkupChange/jumpLinksItem-warn-markup-change.test.ts index 59fa15e07..d47341246 100644 --- a/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnMarkupChange/jumpLinksItem-warn-markup-change.test.ts +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnMarkupChange/jumpLinksItem-warn-markup-change.test.ts @@ -3,17 +3,14 @@ import * as rule from "./jumpLinksItem-warn-markup-change"; ruleTester.run("jumpLinksItem-warn-markup-change", rule, { valid: [ - { - code: ``, - }, { code: `import { JumpLinksItem } from '@someOtherPackage';`, }, ], invalid: [ { - code: `import { JumpLinksItem } from '@patternfly/react-core'; `, - output: `import { JumpLinksItem } from '@patternfly/react-core'; `, + code: `import { JumpLinksItem } from '@patternfly/react-core';`, + output: `import { JumpLinksItem } from '@patternfly/react-core';`, errors: [ { message: `The markup for JumpLinksItem has changed, as it now uses our Button component internally. Additionally, the \`onClick\` prop type has been updated to just \`React.MouseEvent\` (previously \`React.MouseEvent\`).`, diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnMarkupChange/jumpLinksItem-warn-markup-change.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnMarkupChange/jumpLinksItem-warn-markup-change.ts index 70caa4646..b1552c455 100644 --- a/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnMarkupChange/jumpLinksItem-warn-markup-change.ts +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/jumpLinksItemWarnMarkupChange/jumpLinksItem-warn-markup-change.ts @@ -9,8 +9,7 @@ module.exports = { const { imports } = getFromPackage(context, "@patternfly/react-core"); const jumpLinksItemImport = imports.find( - (specifier: { imported: { name: string } }) => - specifier.imported.name === "JumpLinksItem" + (specifier) => specifier.imported.name === "JumpLinksItem" ); return !jumpLinksItemImport @@ -20,8 +19,8 @@ module.exports = { if ( node.specifiers.find( (specifier) => - (specifier as ImportSpecifier)?.imported.name === - jumpLinksItemImport.imported.name + specifier.type === "ImportSpecifier" && + specifier.imported.name === jumpLinksItemImport.imported.name ) ) { context.report({