Skip to content

Commit

Permalink
feat(NotificationBadge) warn about markup updated (#592)
Browse files Browse the repository at this point in the history
* feat(NotificationBadge) warn about markup updated

* fix error type
  • Loading branch information
Dominik-Petrik authored Feb 27, 2024
1 parent 72806cd commit d073617
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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',
},
],
},
],
});
Original file line number Diff line number Diff line change
@@ -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.',
});
}
},
};
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import { NotificationBadge } from '@patternfly/react-core';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import { NotificationBadge } from '@patternfly/react-core';

0 comments on commit d073617

Please sign in to comment.