-
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.
feat(JumpLinks): warned about href and markup/type updates (#575)
* feat(JumpLinks): warned about href and markup/type updates * Separated href rule so it will flag as an error * Added typing to PageSection rules * Updated typing in markup warn rule
- Loading branch information
1 parent
e90502b
commit 0af1541
Showing
13 changed files
with
186 additions
and
36 deletions.
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
3 changes: 3 additions & 0 deletions
3
...-codemods/src/rules/v6/jumpLinksItemHrefRequired/jumpLinksItem-href-required.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 @@ | ||
### jumpLinksItem-href-required [(#10027)](https://github.com/patternfly/patternfly-react/pull/10027) | ||
|
||
The `href` prop on JumpLinksItem is now required. |
35 changes: 35 additions & 0 deletions
35
...in-pf-codemods/src/rules/v6/jumpLinksItemHrefRequired/jumpLinksItem-href-required.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,35 @@ | ||
const ruleTester = require("../../ruletester"); | ||
import * as rule from "./jumpLinksItem-href-required"; | ||
|
||
ruleTester.run("jumpLinksItem-href-required", rule, { | ||
valid: [ | ||
{ | ||
code: `import { JumpLinksItem } from 'someOtherPackage'; <JumpLinksItem />`, | ||
}, | ||
{ | ||
code: `import { JumpLinksItem } from '@patternfly/react-core'; <JumpLinksItem href="someURL" />`, | ||
}, | ||
], | ||
invalid: [ | ||
{ | ||
code: `import { JumpLinksItem } from '@patternfly/react-core'; <JumpLinksItem />`, | ||
output: `import { JumpLinksItem } from '@patternfly/react-core'; <JumpLinksItem />`, | ||
errors: [ | ||
{ | ||
message: `The \`href\` prop on JumpLinksItem is now required.`, | ||
type: "JSXOpeningElement", | ||
}, | ||
], | ||
}, | ||
{ | ||
code: `import { JumpLinksItem } from '@patternfly/react-core'; <JumpLinksItem href />`, | ||
output: `import { JumpLinksItem } from '@patternfly/react-core'; <JumpLinksItem href />`, | ||
errors: [ | ||
{ | ||
message: `The \`href\` prop on JumpLinksItem is now required.`, | ||
type: "JSXOpeningElement", | ||
}, | ||
], | ||
}, | ||
], | ||
}); |
39 changes: 39 additions & 0 deletions
39
...-plugin-pf-codemods/src/rules/v6/jumpLinksItemHrefRequired/jumpLinksItem-href-required.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,39 @@ | ||
import { getFromPackage } from "../../helpers"; | ||
import { Rule } from "eslint"; | ||
import { JSXOpeningElement, JSXAttribute } from "estree-jsx"; | ||
|
||
// https://github.com/patternfly/patternfly-react/pull/10027 | ||
module.exports = { | ||
meta: {}, | ||
create: function (context: Rule.RuleContext) { | ||
const { imports } = getFromPackage(context, "@patternfly/react-core"); | ||
|
||
const jumpLinksItemImport = imports.find( | ||
(specifier) => specifier.imported.name === "JumpLinksItem" | ||
); | ||
|
||
return !jumpLinksItemImport | ||
? {} | ||
: { | ||
JSXOpeningElement(node: JSXOpeningElement) { | ||
if ( | ||
node.name.type === "JSXIdentifier" && | ||
jumpLinksItemImport.local.name === node.name.name | ||
) { | ||
const hrefAttribute = node.attributes.find( | ||
(attribute) => | ||
attribute.type === "JSXAttribute" && | ||
attribute.name.name === "href" | ||
); | ||
|
||
if (!hrefAttribute || !(hrefAttribute as JSXAttribute).value) { | ||
context.report({ | ||
node, | ||
message: "The `href` prop on JumpLinksItem is now required.", | ||
}); | ||
} | ||
} | ||
}, | ||
}; | ||
}, | ||
}; |
8 changes: 8 additions & 0 deletions
8
...gin-pf-codemods/src/rules/v6/jumpLinksItemHrefRequired/jumpLinksItemHrefRequiredInput.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 { JumpLinksItem } from "@patternfly/react-core"; | ||
|
||
export const JumpLinksItemWarnMarkupChangeInput = () => ( | ||
<> | ||
<JumpLinksItem /> | ||
<JumpLinksItem href /> | ||
</> | ||
); |
8 changes: 8 additions & 0 deletions
8
...in-pf-codemods/src/rules/v6/jumpLinksItemHrefRequired/jumpLinksItemHrefRequiredOutput.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 { JumpLinksItem } from "@patternfly/react-core"; | ||
|
||
export const JumpLinksItemWarnMarkupChangeInput = () => ( | ||
<> | ||
<JumpLinksItem /> | ||
<JumpLinksItem href /> | ||
</> | ||
); |
3 changes: 3 additions & 0 deletions
3
.../src/rules/v6/jumpLinksItemWarnMarkupChange/jumpLinksItem-warn-markup-change.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 @@ | ||
### jumpLinksItem-warn-markup-change [(#10027)](https://github.com/patternfly/patternfly-react/pull/10027) | ||
|
||
The markup for JumpLinksItem has changed, as it now uses our Button component internally. Additionally, the `onClick` prop type has been updated to just `React.MouseEvent` (previously `React.MouseEvent<HTMLAnchorElement>`). |
22 changes: 22 additions & 0 deletions
22
...emods/src/rules/v6/jumpLinksItemWarnMarkupChange/jumpLinksItem-warn-markup-change.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,22 @@ | ||
const ruleTester = require("../../ruletester"); | ||
import * as rule from "./jumpLinksItem-warn-markup-change"; | ||
|
||
ruleTester.run("jumpLinksItem-warn-markup-change", rule, { | ||
valid: [ | ||
{ | ||
code: `import { JumpLinksItem } from '@someOtherPackage';`, | ||
}, | ||
], | ||
invalid: [ | ||
{ | ||
code: `import { JumpLinksItem } from '@patternfly/react-core';`, | ||
output: `import { JumpLinksItem } from '@patternfly/react-core';`, | ||
errors: [ | ||
{ | ||
message: `The markup for JumpLinksItem has changed, as it now uses our Button component internally. Additionally, the \`onClick\` prop type has been updated to just \`React.MouseEvent\` (previously \`React.MouseEvent<HTMLAnchorElement>\`).`, | ||
type: "ImportDeclaration", | ||
}, | ||
], | ||
}, | ||
], | ||
}); |
35 changes: 35 additions & 0 deletions
35
...f-codemods/src/rules/v6/jumpLinksItemWarnMarkupChange/jumpLinksItem-warn-markup-change.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 { getFromPackage } from "../../helpers"; | ||
import { Rule } from "eslint"; | ||
import { ImportDeclaration, ImportSpecifier } from "estree-jsx"; | ||
|
||
// https://github.com/patternfly/patternfly-react/pull/10027 | ||
module.exports = { | ||
meta: {}, | ||
create: function (context: Rule.RuleContext) { | ||
const { imports } = getFromPackage(context, "@patternfly/react-core"); | ||
|
||
const jumpLinksItemImport = imports.find( | ||
(specifier) => specifier.imported.name === "JumpLinksItem" | ||
); | ||
|
||
return !jumpLinksItemImport | ||
? {} | ||
: { | ||
ImportDeclaration(node: ImportDeclaration) { | ||
if ( | ||
node.specifiers.find( | ||
(specifier) => | ||
specifier.type === "ImportSpecifier" && | ||
specifier.imported.name === jumpLinksItemImport.imported.name | ||
) | ||
) { | ||
context.report({ | ||
node, | ||
message: | ||
"The markup for JumpLinksItem has changed, as it now uses our Button component internally. Additionally, the `onClick` prop type has been updated to just `React.MouseEvent` (previously `React.MouseEvent<HTMLAnchorElement>`).", | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
}; |
1 change: 1 addition & 0 deletions
1
...odemods/src/rules/v6/jumpLinksItemWarnMarkupChange/jumpLinksItemWarnMarkupChangeInput.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 @@ | ||
import { JumpLinksItem } from "@patternfly/react-core"; |
1 change: 1 addition & 0 deletions
1
...demods/src/rules/v6/jumpLinksItemWarnMarkupChange/jumpLinksItemWarnMarkupChangeOutput.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 @@ | ||
import { JumpLinksItem } from "@patternfly/react-core"; |
38 changes: 19 additions & 19 deletions
38
...codemods/src/rules/v6/pageSectionUpdateVariantValues/pageSection-update-variant-values.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
28 changes: 11 additions & 17 deletions
28
.../rules/v6/pageSectionWarnVariantClassesApplied/pageSection-warn-variantClasses-applied.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