Skip to content

Commit

Permalink
refactor: get rid of nodeIsComponentNamed helper
Browse files Browse the repository at this point in the history
  • Loading branch information
adamviktora committed Aug 26, 2024
1 parent 6ee3bff commit f4b868d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export * from "./importAndExport";
export * from "./includesImport";
export * from "./interfaces";
export * from "./JSXAttributes";
export * from "./nodeIsComponentNamed";
export * from "./nodeMatches";
export * from "./pfPackageMatches";
export * from "./removeElement";
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import {
Node,
} from "estree-jsx";
import {
checkMatchingJSXOpeningElement,
getAttribute,
getAttributeText,
getAttributeValueText,
getChildJSXElementByName,
getDefaultImportsFromPackage,
getExpression,
getFromPackage,
includesImport,
nodeIsComponentNamed,
getChildrenAsAttributeValueText,
getRemoveElementFixes,
} from "../../helpers";
Expand Down Expand Up @@ -149,13 +148,19 @@ module.exports = {
const pkg = "@patternfly/react-core";
const { imports } = getFromPackage(context, pkg);

if (!includesImport(imports, "EmptyState")) {
const emptyStateImport = imports.find(
(specifier) => specifier.imported.name === "EmptyState"
);

if (!emptyStateImport) {
return {};
}

return {
JSXElement(node: JSXElement) {
if (!nodeIsComponentNamed(node, "EmptyState")) {
if (
!checkMatchingJSXOpeningElement(node.openingElement, emptyStateImport)
) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Rule } from "eslint";
import { JSXElement } from "estree-jsx";
import {
checkMatchingJSXOpeningElement,
getAttribute,
getAttributeText,
getExpression,
getFromPackage,
includesImport,
nodeIsComponentNamed,
} from "../../helpers";

// https://github.com/patternfly/patternfly-react/pull/10107
Expand All @@ -25,7 +25,12 @@ module.exports = {

return {
JSXElement(node: JSXElement) {
if (!nodeIsComponentNamed(node, "LoginMainFooterLinksItem")) {
if (
!checkMatchingJSXOpeningElement(
node.openingElement,
loginMainFooterLinksItemImport
)
) {
return;
}

Expand Down

0 comments on commit f4b868d

Please sign in to comment.