-
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(Modal): promoted Next implementation (#660)
* feat(Modal): promoted Next implementation * Created test helpers file
- Loading branch information
1 parent
258601d
commit 9a08828
Showing
12 changed files
with
381 additions
and
24 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
packages/eslint-plugin-pf-codemods/src/rules/helpers/testHelpers.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,25 @@ | ||
import { RuleTester } from "eslint"; | ||
|
||
export type ValidTests = Array<string | RuleTester.ValidTestCase>; | ||
export type InvalidTests = RuleTester.InvalidTestCase[]; | ||
type TestErrors = { | ||
message: string; | ||
type: string; | ||
}[]; | ||
|
||
export function createValidTest(code: string) { | ||
return { | ||
code, | ||
}; | ||
} | ||
export function createInvalidTest( | ||
code: string, | ||
output: string, | ||
errors: TestErrors | ||
) { | ||
return { | ||
code, | ||
output, | ||
errors, | ||
}; | ||
} |
17 changes: 17 additions & 0 deletions
17
...ages/eslint-plugin-pf-codemods/src/rules/v6/modalDeprecated/modal-deprecated.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,17 @@ | ||
### modal-deprecated [(#10358)](https://github.com/patternfly/patternfly-react/pull/10358) | ||
|
||
Our previous implementation of Modal has been deprecated. This rule will update import paths to our deprecated directory, but we recommend using our newly promoted implementation. | ||
|
||
#### Examples | ||
|
||
In: | ||
|
||
```jsx | ||
%inputExample% | ||
``` | ||
|
||
Out: | ||
|
||
```jsx | ||
%outputExample% | ||
``` |
126 changes: 126 additions & 0 deletions
126
packages/eslint-plugin-pf-codemods/src/rules/v6/modalDeprecated/modal-deprecated.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,126 @@ | ||
const ruleTester = require("../../ruletester"); | ||
import * as rule from "./modal-deprecated"; | ||
import { | ||
ValidTests, | ||
InvalidTests, | ||
createValidTest, | ||
createInvalidTest, | ||
} from "../../helpers/testHelpers"; | ||
|
||
const specifiersToMove = [ | ||
"Modal", | ||
"ModalVariant", | ||
"ModalBox", | ||
"ModalBoxBody", | ||
"ModalBoxCloseButton", | ||
"ModalBoxHeader", | ||
"ModalBoxFooter", | ||
"ModalContent", | ||
]; | ||
|
||
const validTests: ValidTests = []; | ||
const invalidTests: InvalidTests = []; | ||
|
||
specifiersToMove.forEach((specifier) => { | ||
if (!specifier.endsWith("Variant")) { | ||
validTests.push(createValidTest(`<${specifier} />`)); | ||
} | ||
validTests.push( | ||
createValidTest( | ||
`import { ${specifier} /* data-codemods */ } from '@patternfly/react-core';` | ||
) | ||
); | ||
validTests.push( | ||
createValidTest( | ||
`import { ${specifier} } from '@patternfly/react-core/deprecated';` | ||
) | ||
); | ||
validTests.push( | ||
createValidTest( | ||
`export { ${specifier} /* data-codemods */ } from '@patternfly/react-core';` | ||
) | ||
); | ||
validTests.push( | ||
createValidTest( | ||
`export { ${specifier} } from '@patternfly/react-core/deprecated';` | ||
) | ||
); | ||
|
||
const errorMessage = `${specifier} has been deprecated. This rule will update import paths to our deprecated directory, but we recommend using our newly promoted Modal implementation.`; | ||
invalidTests.push( | ||
createInvalidTest( | ||
`import { ${specifier} } from '@patternfly/react-core';`, | ||
`import {\n\t${specifier}\n} from '@patternfly/react-core/deprecated';`, | ||
[{ message: errorMessage, type: "ImportDeclaration" }] | ||
) | ||
); | ||
invalidTests.push( | ||
createInvalidTest( | ||
`import { ${specifier} as CustomSpecifier } from '@patternfly/react-core';`, | ||
`import {\n\t${specifier} as CustomSpecifier\n} from '@patternfly/react-core/deprecated';`, | ||
[{ message: errorMessage, type: "ImportDeclaration" }] | ||
) | ||
); | ||
invalidTests.push( | ||
createInvalidTest( | ||
`import { ${specifier} } from '@patternfly/react-core/dist/esm/components/Modal/index.js';`, | ||
`import {\n\t${specifier}\n} from '@patternfly/react-core/dist/esm/deprecated/components/Modal/index.js';`, | ||
[{ message: errorMessage, type: "ImportDeclaration" }] | ||
) | ||
); | ||
invalidTests.push( | ||
createInvalidTest( | ||
`import { ${specifier} } from '@patternfly/react-core/dist/js/components/Modal/index.js';`, | ||
`import {\n\t${specifier}\n} from '@patternfly/react-core/deprecated';`, | ||
[{ message: errorMessage, type: "ImportDeclaration" }] | ||
) | ||
); | ||
invalidTests.push( | ||
createInvalidTest( | ||
`import { ${specifier} } from '@patternfly/react-core/dist/dynamic/components/Modal/index.js';`, | ||
`import {\n\t${specifier}\n} from '@patternfly/react-core/deprecated';`, | ||
[{ message: errorMessage, type: "ImportDeclaration" }] | ||
) | ||
); | ||
invalidTests.push( | ||
createInvalidTest( | ||
`export { ${specifier} } from '@patternfly/react-core';`, | ||
`export {\n\t${specifier}\n} from '@patternfly/react-core/deprecated';`, | ||
[{ message: errorMessage, type: "ExportNamedDeclaration" }] | ||
) | ||
); | ||
invalidTests.push( | ||
createInvalidTest( | ||
`export { ${specifier} } from '@patternfly/react-core/dist/esm/components/Modal/index.js';`, | ||
`export {\n\t${specifier}\n} from '@patternfly/react-core/dist/esm/deprecated/components/Modal/index.js';`, | ||
[{ message: errorMessage, type: "ExportNamedDeclaration" }] | ||
) | ||
); | ||
invalidTests.push( | ||
createInvalidTest( | ||
`export { ${specifier} } from '@patternfly/react-core/dist/js/components/Modal/index.js';`, | ||
`export {\n\t${specifier}\n} from '@patternfly/react-core/deprecated';`, | ||
[{ message: errorMessage, type: "ExportNamedDeclaration" }] | ||
) | ||
); | ||
invalidTests.push( | ||
createInvalidTest( | ||
`export { ${specifier} } from '@patternfly/react-core/dist/dynamic/components/Modal/index.js';`, | ||
`export {\n\t${specifier}\n} from '@patternfly/react-core/deprecated';`, | ||
[{ message: errorMessage, type: "ExportNamedDeclaration" }] | ||
) | ||
); | ||
invalidTests.push( | ||
createInvalidTest( | ||
`import { ${specifier}, Button } from '@patternfly/react-core';`, | ||
`import {\n\tButton\n} from '@patternfly/react-core'; | ||
import {\n\t${specifier}\n} from '@patternfly/react-core/deprecated';`, | ||
[{ message: errorMessage, type: "ImportDeclaration" }] | ||
) | ||
); | ||
}); | ||
|
||
ruleTester.run("modal-deprecated", rule, { | ||
valid: validTests, | ||
invalid: invalidTests, | ||
}); |
29 changes: 29 additions & 0 deletions
29
packages/eslint-plugin-pf-codemods/src/rules/v6/modalDeprecated/modal-deprecated.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,29 @@ | ||
import { moveSpecifiers } from "../../helpers"; | ||
|
||
// https://github.com/patternfly/patternfly-react/pull/10358 | ||
|
||
const specifiersToMove = [ | ||
"Modal", | ||
"ModalVariant", | ||
"ModalBox", | ||
"ModalBoxBody", | ||
"ModalBoxCloseButton", | ||
"ModalBoxHeader", | ||
"ModalBoxFooter", | ||
"ModalContent", | ||
]; | ||
|
||
const fromPackage = "@patternfly/react-core"; | ||
const toPackage = "@patternfly/react-core/deprecated"; | ||
const messageAfterImportNameChange = | ||
"been deprecated. This rule will update import paths to our deprecated directory, but we recommend using our newly promoted Modal implementation."; | ||
|
||
module.exports = { | ||
meta: { fixable: "code" }, | ||
create: moveSpecifiers( | ||
specifiersToMove, | ||
fromPackage, | ||
toPackage, | ||
messageAfterImportNameChange | ||
), | ||
}; |
1 change: 1 addition & 0 deletions
1
packages/eslint-plugin-pf-codemods/src/rules/v6/modalDeprecated/modalDeprecatedInput.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 { Modal } from "@patternfly/react-core"; |
3 changes: 3 additions & 0 deletions
3
packages/eslint-plugin-pf-codemods/src/rules/v6/modalDeprecated/modalDeprecatedOutput.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,3 @@ | ||
import { | ||
Modal | ||
} from '@patternfly/react-core/deprecated'; |
17 changes: 17 additions & 0 deletions
17
.../eslint-plugin-pf-codemods/src/rules/v6/modalNextPromoted/modalNext-promoted.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,17 @@ | ||
### modalNext-promoted [(#10358)](https://github.com/patternfly/patternfly-react/pull/10358) | ||
|
||
Our Next implementation of Modal has been promoted as our recommended implementation. This rule will update import paths. | ||
|
||
#### Examples | ||
|
||
In: | ||
|
||
```jsx | ||
%inputExample% | ||
``` | ||
|
||
Out: | ||
|
||
```jsx | ||
%outputExample% | ||
``` |
111 changes: 111 additions & 0 deletions
111
packages/eslint-plugin-pf-codemods/src/rules/v6/modalNextPromoted/modalNext-promoted.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,111 @@ | ||
const ruleTester = require("../../ruletester"); | ||
import * as rule from "./modalNext-promoted"; | ||
import { | ||
ValidTests, | ||
InvalidTests, | ||
createValidTest, | ||
createInvalidTest, | ||
} from "../../helpers/testHelpers"; | ||
|
||
const specifiersToMove = ["Modal", "ModalBody", "ModalHeader", "ModalFooter"]; | ||
const validTests: ValidTests = []; | ||
const invalidTests: InvalidTests = []; | ||
|
||
specifiersToMove.forEach((specifier) => { | ||
if (!specifier.endsWith("Variant")) { | ||
validTests.push(createValidTest(`<${specifier} />`)); | ||
} | ||
validTests.push( | ||
createValidTest( | ||
`import { ${specifier} /* data-codemods */ } from '@patternfly/react-core';` | ||
) | ||
); | ||
validTests.push( | ||
createValidTest(`import { ${specifier} } from '@patternfly/react-core';`) | ||
); | ||
validTests.push( | ||
createValidTest( | ||
`export { ${specifier} /* data-codemods */ } from '@patternfly/react-core';` | ||
) | ||
); | ||
validTests.push( | ||
createValidTest(`export { ${specifier} } from '@patternfly/react-core';`) | ||
); | ||
|
||
const errorMessage = `${specifier} has been promoted. This rule will update import paths.`; | ||
invalidTests.push( | ||
createInvalidTest( | ||
`import { ${specifier} } from '@patternfly/react-core/next';`, | ||
`import {\n\t${specifier} /* data-codemods */\n} from '@patternfly/react-core';`, | ||
[{ message: errorMessage, type: "ImportDeclaration" }] | ||
) | ||
); | ||
invalidTests.push( | ||
createInvalidTest( | ||
`import { ${specifier} as CustomSpecifier } from '@patternfly/react-core/next';`, | ||
`import {\n\t${specifier} as CustomSpecifier /* data-codemods */\n} from '@patternfly/react-core';`, | ||
[{ message: errorMessage, type: "ImportDeclaration" }] | ||
) | ||
); | ||
invalidTests.push( | ||
createInvalidTest( | ||
`import { ${specifier} } from '@patternfly/react-core/dist/esm/next/components/Modal/index.js';`, | ||
`import {\n\t${specifier} /* data-codemods */\n} from '@patternfly/react-core/dist/esm/components/Modal/index.js';`, | ||
[{ message: errorMessage, type: "ImportDeclaration" }] | ||
) | ||
); | ||
invalidTests.push( | ||
createInvalidTest( | ||
`import { ${specifier} } from '@patternfly/react-core/dist/js/next/components/Modal/index.js';`, | ||
`import {\n\t${specifier} /* data-codemods */\n} from '@patternfly/react-core';`, | ||
[{ message: errorMessage, type: "ImportDeclaration" }] | ||
) | ||
); | ||
invalidTests.push( | ||
createInvalidTest( | ||
`import { ${specifier} } from '@patternfly/react-core/dist/dynamic/next/components/Modal/index.js';`, | ||
`import {\n\t${specifier} /* data-codemods */\n} from '@patternfly/react-core';`, | ||
[{ message: errorMessage, type: "ImportDeclaration" }] | ||
) | ||
); | ||
invalidTests.push( | ||
createInvalidTest( | ||
`export { ${specifier} } from '@patternfly/react-core/next';`, | ||
`export {\n\t${specifier} /* data-codemods */\n} from '@patternfly/react-core';`, | ||
[{ message: errorMessage, type: "ExportNamedDeclaration" }] | ||
) | ||
); | ||
invalidTests.push( | ||
createInvalidTest( | ||
`export { ${specifier} } from '@patternfly/react-core/dist/esm/next/components/Modal/index.js';`, | ||
`export {\n\t${specifier} /* data-codemods */\n} from '@patternfly/react-core/dist/esm/components/Modal/index.js';`, | ||
[{ message: errorMessage, type: "ExportNamedDeclaration" }] | ||
) | ||
); | ||
invalidTests.push( | ||
createInvalidTest( | ||
`export { ${specifier} } from '@patternfly/react-core/dist/js/next/components/Modal/index.js';`, | ||
`export {\n\t${specifier} /* data-codemods */\n} from '@patternfly/react-core';`, | ||
[{ message: errorMessage, type: "ExportNamedDeclaration" }] | ||
) | ||
); | ||
invalidTests.push( | ||
createInvalidTest( | ||
`export { ${specifier} } from '@patternfly/react-core/dist/dynamic/next/components/Modal/index.js';`, | ||
`export {\n\t${specifier} /* data-codemods */\n} from '@patternfly/react-core';`, | ||
[{ message: errorMessage, type: "ExportNamedDeclaration" }] | ||
) | ||
); | ||
invalidTests.push( | ||
createInvalidTest( | ||
`import { ${specifier} } from '@patternfly/react-core/next';\nimport { Button } from '@patternfly/react-core';`, | ||
`\nimport {\n\tButton,\n\t${specifier} /* data-codemods */\n} from '@patternfly/react-core';`, | ||
[{ message: errorMessage, type: "ImportDeclaration" }] | ||
) | ||
); | ||
}); | ||
|
||
ruleTester.run("modalNext-promoted", rule, { | ||
valid: validTests, | ||
invalid: invalidTests, | ||
}); |
20 changes: 20 additions & 0 deletions
20
packages/eslint-plugin-pf-codemods/src/rules/v6/modalNextPromoted/modalNext-promoted.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,20 @@ | ||
import { moveSpecifiers } from "../../helpers"; | ||
|
||
// https://github.com/patternfly/patternfly-react/pull/10358 | ||
|
||
const specifiersToMove = ["Modal", "ModalBody", "ModalHeader", "ModalFooter"]; | ||
|
||
const fromPackage = "@patternfly/react-core/next"; | ||
const toPackage = "@patternfly/react-core"; | ||
const messageAfterImportNameChange = | ||
"been promoted. This rule will update import paths."; | ||
|
||
module.exports = { | ||
meta: { fixable: "code" }, | ||
create: moveSpecifiers( | ||
specifiersToMove, | ||
fromPackage, | ||
toPackage, | ||
messageAfterImportNameChange | ||
), | ||
}; |
1 change: 1 addition & 0 deletions
1
packages/eslint-plugin-pf-codemods/src/rules/v6/modalNextPromoted/modalNextPromotedInput.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 { Modal } from "@patternfly/react-core/next"; |
3 changes: 3 additions & 0 deletions
3
...ages/eslint-plugin-pf-codemods/src/rules/v6/modalNextPromoted/modalNextPromotedOutput.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,3 @@ | ||
import { | ||
Modal /* data-codemods */ | ||
} from '@patternfly/react-core'; |
Oops, something went wrong.