diff --git a/packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts b/packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts index 9ba0caa98..e8e21a3c5 100644 --- a/packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts +++ b/packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts @@ -23,6 +23,7 @@ export const warningRules = [ "label-warn-truncated-default", "menuToggle-warn-iconOnly-toggle", "nav-warn-flyouts-now-inline", + "notificationBadge-warn-markup-change", "overflowMenu-warn-updated-dropdownItem", "pageSection-warn-variantClasses-applied", "popover-warn-appendTo-default", diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/notificationBadgeWarnMarkupChange/notificationBadge-warn-markup-change.md b/packages/eslint-plugin-pf-codemods/src/rules/v6/notificationBadgeWarnMarkupChange/notificationBadge-warn-markup-change.md new file mode 100644 index 000000000..b2959e9fe --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/notificationBadgeWarnMarkupChange/notificationBadge-warn-markup-change.md @@ -0,0 +1,3 @@ +### notificationBadge-warn-markup-change [(#10020)](https://github.com/patternfly/patternfly-react/pull/10020) + +The markup for NotificationBadge has changed, as it now uses stateful button internally. diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/notificationBadgeWarnMarkupChange/notificationBadge-warn-markup-change.test.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/notificationBadgeWarnMarkupChange/notificationBadge-warn-markup-change.test.ts new file mode 100644 index 000000000..d898538d1 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/notificationBadgeWarnMarkupChange/notificationBadge-warn-markup-change.test.ts @@ -0,0 +1,22 @@ +const ruleTester = require('../../ruletester'); +import * as rule from './notificationBadge-warn-markup-change'; + +ruleTester.run('notificationBadge-warn-markup-change', rule, { + valid: [ + { + code: `import { NotificationBadge } from '@someOtherPackage';`, + }, + ], + invalid: [ + { + code: `import { NotificationBadge } from '@patternfly/react-core';`, + output: `import { NotificationBadge } from '@patternfly/react-core';`, + errors: [ + { + message: `The markup for NotificationBadge has changed, as it now uses stateful button internally.`, + type: 'ImportDeclaration', + }, + ], + }, + ], +}); diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/notificationBadgeWarnMarkupChange/notificationBadge-warn-markup-change.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/notificationBadgeWarnMarkupChange/notificationBadge-warn-markup-change.ts new file mode 100644 index 000000000..c851b5f75 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/notificationBadgeWarnMarkupChange/notificationBadge-warn-markup-change.ts @@ -0,0 +1,36 @@ +import { getFromPackage } from '../../helpers'; +import { Rule } from 'eslint'; +import { ImportDeclaration } from 'estree-jsx'; + +// https://github.com/patternfly/patternfly-react/pull/10020 +module.exports = { + meta: {}, + create: function (context: Rule.RuleContext) { + const { imports } = getFromPackage(context, '@patternfly/react-core'); + + const notificationBadgeImport = imports.find( + (specifier) => specifier.imported.name === 'NotificationBadge' + ); + + return !notificationBadgeImport + ? {} + : { + ImportDeclaration(node: ImportDeclaration) { + if ( + node.specifiers.find( + (specifier) => + specifier.type === 'ImportSpecifier' && + specifier.imported.name === + notificationBadgeImport.imported.name + ) + ) { + context.report({ + node, + message: + 'The markup for NotificationBadge has changed, as it now uses stateful button internally.', + }); + } + }, + }; + }, +}; diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/notificationBadgeWarnMarkupChange/notificationBadgeWarnMarkupChangeInput.tsx b/packages/eslint-plugin-pf-codemods/src/rules/v6/notificationBadgeWarnMarkupChange/notificationBadgeWarnMarkupChangeInput.tsx new file mode 100644 index 000000000..b4b29d14a --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/notificationBadgeWarnMarkupChange/notificationBadgeWarnMarkupChangeInput.tsx @@ -0,0 +1 @@ +import { NotificationBadge } from '@patternfly/react-core'; diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/notificationBadgeWarnMarkupChange/notificationBadgeWarnMarkupChangeOutput.tsx b/packages/eslint-plugin-pf-codemods/src/rules/v6/notificationBadgeWarnMarkupChange/notificationBadgeWarnMarkupChangeOutput.tsx new file mode 100644 index 000000000..b4b29d14a --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/notificationBadgeWarnMarkupChange/notificationBadgeWarnMarkupChangeOutput.tsx @@ -0,0 +1 @@ +import { NotificationBadge } from '@patternfly/react-core';