-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(LoginPage): updated markup for LoginMainHeader #752
Merged
adamviktora
merged 5 commits into
patternfly:main
from
thatblindgeye:loginPageUpdateMarkup
Sep 2, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ba367d3
fix(LoginPage): updated markup for LoginMainHeader
thatblindgeye 8440fec
Added description to importdec matches helper
thatblindgeye 8f56df8
PR feedback
thatblindgeye 5f60623
Updated import declaration to return boolean
thatblindgeye 3d92448
Merge branch 'main' into loginPageUpdateMarkup
adamviktora File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 /> | ||
</> | ||
); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you refactor this helper to return only boolean? Or if there is a purpose of returning the specifier to return it
as ImportSpecifier
with the type casting. Depends on whether we need the specifier in a return value, but in the array case it would just return the first specifier, so maybe using.some
everywhere (instead of.find
) would be better.