-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(LoginPage): updated markup for LoginMainHeader (#752)
* fix(LoginPage): updated markup for LoginMainHeader * Added description to importdec matches helper * PR feedback * Updated import declaration to return boolean --------- Co-authored-by: adamviktora <[email protected]>
- Loading branch information
1 parent
204d882
commit 722b9e6
Showing
10 changed files
with
180 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...eslint-plugin-pf-codemods/src/rules/helpers/nodeMatches/checkMatchingImportDeclaration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { ImportDeclaration, ImportSpecifier } from "estree-jsx"; | ||
import { pfPackageMatches } from "../pfPackageMatches"; | ||
|
||
function checkSpecifierExists( | ||
node: ImportDeclaration, | ||
importSpecifier: ImportSpecifier | ||
) { | ||
return node.specifiers.some( | ||
(specifier) => | ||
specifier.type === "ImportSpecifier" && | ||
specifier.imported.name === importSpecifier.imported.name | ||
); | ||
} | ||
|
||
/** Used to check whether the current ImportDeclaration node matches at least 1 of the import specifiers. */ | ||
export function checkMatchingImportDeclaration( | ||
node: ImportDeclaration, | ||
imports: ImportSpecifier | ImportSpecifier[], | ||
packageName: string = "@patternfly/react-core" | ||
) { | ||
if (!pfPackageMatches(packageName, node.source.value)) { | ||
return false; | ||
} | ||
|
||
if (Array.isArray(imports)) { | ||
return imports.some((imp) => checkSpecifierExists(node, imp)); | ||
} | ||
|
||
return checkSpecifierExists(node, imports); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/eslint-plugin-pf-codemods/src/rules/helpers/pfPackageMatches.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...ules/v6/loginMainHeaderWarnUpdatedMarkup/loginMainHeader-warn-updated-markup.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
### loginMainHeader-warn-updated-markup [(#10880)](https://github.com/patternfly/patternfly-react/pull/10880) | ||
|
||
The markup for LoginMainHeader - which is used internally within LoginPage - has been updated, now using a `div` wrapper instead of a `header` element wrapper. |
91 changes: 91 additions & 0 deletions
91
...src/rules/v6/loginMainHeaderWarnUpdatedMarkup/loginMainHeader-warn-updated-markup.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
const ruleTester = require("../../ruletester"); | ||
import * as rule from "./loginMainHeader-warn-updated-markup"; | ||
|
||
ruleTester.run("loginMainHeader-warn-updated-markup", rule, { | ||
valid: [ | ||
{ | ||
code: `<LoginMainHeader />`, | ||
}, | ||
{ | ||
code: `import { LoginMainHeader } from 'somewhere-else'`, | ||
}, | ||
{ | ||
code: `<LoginPage />`, | ||
}, | ||
{ | ||
code: `import { LoginPage } from 'somewhere-else'`, | ||
}, | ||
], | ||
invalid: [ | ||
{ | ||
code: `import { LoginMainHeader } from '@patternfly/react-core';`, | ||
output: `import { LoginMainHeader } from '@patternfly/react-core';`, | ||
errors: [ | ||
{ | ||
message: `The markup for LoginMainHeader has been updated, now using a div wrapper instead of a header element wrapper.`, | ||
type: "ImportDeclaration", | ||
}, | ||
], | ||
}, | ||
{ | ||
code: `import { LoginPage } from '@patternfly/react-core';`, | ||
output: `import { LoginPage } from '@patternfly/react-core';`, | ||
errors: [ | ||
{ | ||
message: `The markup for LoginMainHeader (which is used internally within LoginPage) has been updated, now using a div wrapper instead of a header element wrapper.`, | ||
type: "ImportDeclaration", | ||
}, | ||
], | ||
}, | ||
{ | ||
code: `import { LoginPage, LoginMainHeader, Button } from '@patternfly/react-core';`, | ||
output: `import { LoginPage, LoginMainHeader, Button } from '@patternfly/react-core';`, | ||
errors: [ | ||
{ | ||
message: `The markup for LoginMainHeader (which is used internally within LoginPage) has been updated, now using a div wrapper instead of a header element wrapper.`, | ||
type: "ImportDeclaration", | ||
}, | ||
], | ||
}, | ||
{ | ||
code: `import { LoginMainHeader as CustomThing } from '@patternfly/react-core';`, | ||
output: `import { LoginMainHeader as CustomThing } from '@patternfly/react-core';`, | ||
errors: [ | ||
{ | ||
message: `The markup for LoginMainHeader has been updated, now using a div wrapper instead of a header element wrapper.`, | ||
type: "ImportDeclaration", | ||
}, | ||
], | ||
}, | ||
{ | ||
code: `import { LoginMainHeader } from '@patternfly/react-core/dist/esm/components/LoginPage/index.js';`, | ||
output: `import { LoginMainHeader } from '@patternfly/react-core/dist/esm/components/LoginPage/index.js';`, | ||
errors: [ | ||
{ | ||
message: `The markup for LoginMainHeader has been updated, now using a div wrapper instead of a header element wrapper.`, | ||
type: "ImportDeclaration", | ||
}, | ||
], | ||
}, | ||
{ | ||
code: `import { LoginMainHeader } from '@patternfly/react-core/dist/js/components/LoginPage/index.js';`, | ||
output: `import { LoginMainHeader } from '@patternfly/react-core/dist/js/components/LoginPage/index.js';`, | ||
errors: [ | ||
{ | ||
message: `The markup for LoginMainHeader has been updated, now using a div wrapper instead of a header element wrapper.`, | ||
type: "ImportDeclaration", | ||
}, | ||
], | ||
}, | ||
{ | ||
code: `import { LoginMainHeader } from '@patternfly/react-core/dist/dynamic/components/LoginPage/index.js';`, | ||
output: `import { LoginMainHeader } from '@patternfly/react-core/dist/dynamic/components/LoginPage/index.js';`, | ||
errors: [ | ||
{ | ||
message: `The markup for LoginMainHeader has been updated, now using a div wrapper instead of a header element wrapper.`, | ||
type: "ImportDeclaration", | ||
}, | ||
], | ||
}, | ||
], | ||
}); |
35 changes: 35 additions & 0 deletions
35
...mods/src/rules/v6/loginMainHeaderWarnUpdatedMarkup/loginMainHeader-warn-updated-markup.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Rule } from "eslint"; | ||
import { ImportDeclaration } from "estree-jsx"; | ||
import { getFromPackage, checkMatchingImportDeclaration } from "../../helpers"; | ||
|
||
// https://github.com/patternfly/patternfly-react/pull/10880 | ||
module.exports = { | ||
meta: {}, | ||
create: function (context: Rule.RuleContext) { | ||
const basePackage = "@patternfly/react-core"; | ||
const { imports: loginImports } = getFromPackage(context, basePackage, [ | ||
"LoginPage", | ||
"LoginMainHeader", | ||
]); | ||
|
||
return !loginImports.length | ||
? {} | ||
: { | ||
ImportDeclaration(node: ImportDeclaration) { | ||
if (checkMatchingImportDeclaration(node, loginImports)) { | ||
const hasLoginPageImport = loginImports.find( | ||
(imp) => imp.imported.name === "LoginPage" | ||
); | ||
context.report({ | ||
node, | ||
message: `The markup for LoginMainHeader${ | ||
hasLoginPageImport | ||
? " (which is used internally within LoginPage)" | ||
: "" | ||
} has been updated, now using a div wrapper instead of a header element wrapper.`, | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
}; |
8 changes: 8 additions & 0 deletions
8
...s/src/rules/v6/loginMainHeaderWarnUpdatedMarkup/loginMainHeaderWarnUpdatedMarkupInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { LoginMainHeader, LoginPage } from "@patternfly/react-core"; | ||
|
||
export const LoginMainHeaderWarnUpdatedMarkupInput = () => ( | ||
<> | ||
<LoginPage /> | ||
<LoginMainHeader /> | ||
</> | ||
); |
8 changes: 8 additions & 0 deletions
8
.../src/rules/v6/loginMainHeaderWarnUpdatedMarkup/loginMainHeaderWarnUpdatedMarkupOutput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { LoginMainHeader, LoginPage } from "@patternfly/react-core"; | ||
|
||
export const LoginMainHeaderWarnUpdatedMarkupInput = () => ( | ||
<> | ||
<LoginPage /> | ||
<LoginMainHeader /> | ||
</> | ||
); |