-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(SimpleFileUpload): added rule to warn about component changes (#570
- Loading branch information
1 parent
fee9102
commit fa19da5
Showing
6 changed files
with
96 additions
and
0 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
5 changes: 5 additions & 0 deletions
5
...emods/src/rules/v6/simpleFileUploadWarnChanges/simpleFileUpload-warn-changes.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,5 @@ | ||
### simpleFileUpload-warn-changes [(#10026)](https://github.com/patternfly/patternfly-react/pull/10026) | ||
|
||
The `aria-describedby` attribute was removed from the TextInput within the SimpleFileUpload, and the `id` attribute was removed from the "browse" button. Instead use the new `browseButtonAriaDescribedby` prop to provide a description to the browse button. | ||
|
||
Additionally, we recommend using our FileUploadHelperText component as a child to the FileUpload, instead of using our FormHelperText (the previous recommendation). |
43 changes: 43 additions & 0 deletions
43
...f-codemods/src/rules/v6/simpleFileUploadWarnChanges/simpleFileUpload-warn-changes.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,43 @@ | ||
const ruleTester = require("../../ruletester"); | ||
import * as rule from "./simpleFileUpload-warn-changes"; | ||
|
||
ruleTester.run("simpleFileUpload-warn-changes", rule, { | ||
valid: [ | ||
{ | ||
code: `<SimpleFileUpload notAThing />`, | ||
}, | ||
{ | ||
code: `import { SimpleFileUpload } from '@patternfly/some-other-package';`, | ||
}, | ||
{ | ||
code: `import { Alert } from '@patternfly/react-core';`, | ||
}, | ||
], | ||
invalid: [ | ||
{ | ||
code: `import { SimpleFileUpload } from '@patternfly/react-core';`, | ||
output: `import { SimpleFileUpload } from '@patternfly/react-core';`, | ||
errors: [ | ||
{ | ||
message: `The \`aria-describedby\` attribute was removed from the TextInput within the SimpleFileUpload, and the \`id\` attribute was removed from the "browse" button. Instead use the new \`browseButtonAriaDescribedby\` prop to provide a description to the browse button. | ||
Additionally, we recommend using our FileUploadHelperText component as a child to the FileUpload, instead of using our FormHelperText (the previous recommendation).`, | ||
type: "ImportDeclaration", | ||
}, | ||
], | ||
}, | ||
// Test that a warning only gets flagged once | ||
{ | ||
code: `import { SimpleFileUpload } from '@patternfly/react-core'; import { Alert } from '@patternfly/react-core';`, | ||
output: `import { SimpleFileUpload } from '@patternfly/react-core'; import { Alert } from '@patternfly/react-core';`, | ||
errors: [ | ||
{ | ||
message: `The \`aria-describedby\` attribute was removed from the TextInput within the SimpleFileUpload, and the \`id\` attribute was removed from the "browse" button. Instead use the new \`browseButtonAriaDescribedby\` prop to provide a description to the browse button. | ||
Additionally, we recommend using our FileUploadHelperText component as a child to the FileUpload, instead of using our FormHelperText (the previous recommendation).`, | ||
type: "ImportDeclaration", | ||
}, | ||
], | ||
}, | ||
], | ||
}); |
43 changes: 43 additions & 0 deletions
43
...gin-pf-codemods/src/rules/v6/simpleFileUploadWarnChanges/simpleFileUpload-warn-changes.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,43 @@ | ||
import { getFromPackage } from "../../helpers"; | ||
|
||
// https://github.com/patternfly/patternfly-react/pull/10026 | ||
module.exports = { | ||
meta: {}, | ||
create: function (context: { | ||
report: (arg0: { | ||
node: any; | ||
message: string; | ||
fix?(fixer: any): any; | ||
}) => void; | ||
}) { | ||
const { imports } = getFromPackage(context, "@patternfly/react-core"); | ||
|
||
const simpleFileUploadImport = imports.find( | ||
(specifier: { imported: { name: string } }) => | ||
specifier.imported.name === "SimpleFileUpload" | ||
); | ||
|
||
return !simpleFileUploadImport | ||
? {} | ||
: { | ||
ImportDeclaration(node: { | ||
specifiers: { imported: { name: string } }[]; | ||
}) { | ||
if ( | ||
node.specifiers.find( | ||
(specifier: { imported: { name: string } }) => | ||
specifier.imported.name === | ||
simpleFileUploadImport.imported.name | ||
) | ||
) { | ||
context.report({ | ||
node, | ||
message: `The \`aria-describedby\` attribute was removed from the TextInput within the SimpleFileUpload, and the \`id\` attribute was removed from the "browse" button. Instead use the new \`browseButtonAriaDescribedby\` prop to provide a description to the browse button. | ||
Additionally, we recommend using our FileUploadHelperText component as a child to the FileUpload, instead of using our FormHelperText (the previous recommendation).`, | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
}; |
2 changes: 2 additions & 0 deletions
2
...pf-codemods/src/rules/v6/simpleFileUploadWarnChanges/simpleFileUploadWarnChangesInput.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,2 @@ | ||
import { SimpleFileUpload } from "@patternfly/react-core"; | ||
import { SomethingElse } from "@patternfly/react-core"; |
2 changes: 2 additions & 0 deletions
2
...f-codemods/src/rules/v6/simpleFileUploadWarnChanges/simpleFileUploadWarnChangesOutput.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,2 @@ | ||
import { SimpleFileUpload } from "@patternfly/react-core"; | ||
import { SomethingElse } from "@patternfly/react-core"; |