Skip to content

Commit ce42c3e

Browse files
authored
Update README (#65)
* start * update readme and a few rules
1 parent fa82e83 commit ce42c3e

File tree

7 files changed

+808
-218
lines changed

7 files changed

+808
-218
lines changed

CONTRIBUTING.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# pf-codemods
2+
An eslint plugin (with an extra CLI utility) to help ease products transitioning to our new major @patternfly/react-core 4.0.0 release.
3+
4+
## Usage
5+
6+
```sh
7+
npx pf-codemods ./path-to-src
8+
```
9+
10+
## Goals
11+
- We want to minimize code changes and respect existing code
12+
- We only want to make safe modifications
13+
- Don't touch code that might not be PatternFly
14+
15+
## redallen rationale
16+
- Most consumers are using JSX, so we can write rules that target JSXElements
17+
- When they're using React.createElement or React.cloneElement that introduces unsafe complications
18+
19+
## Design
20+
- Use a JSX parser that leaves formatting alone as much as possible
21+
- Add basic ESM import parsing to make sure we're only modifying PatternFly `<Button>`s
22+
23+
## Development
24+
This is what @redallen does to develop a rule:
25+
1. ~~Copy a similar rule from `eslint-plugin-pf-codemods/lib/rules/*`~~
26+
2. ~~Add it to the `rules` object at the top of `eslint-plugin-pf-codemods/index.js`~~
27+
3. ~~Copy a test at `test/rules/*` and write your test cases.~~
28+
29+
We now have a generator.
30+
1. Run `node generate new-rule-name` to create the rule files
31+
2. Run `node test/rules/new-rule-name.js` to test the rule
32+
33+
If you're having trouble writing a rule, you can:
34+
1. Put code into an AST explorer like https://astexplorer.net/ to inspect all the AST nodes
35+
2. `console.dir(node, { depth: 5 })` to better inspect a `node` you're dealing with
36+
3. Write rule targeting an AST node that has all the information you need. Confirm AST node exists in `lib/rules/ast-node-types.d.ts`.
37+
4. Ask zallen on the RHUX or PatternFly Slack

README.md

Lines changed: 0 additions & 37 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages/pf-codemods/README.md

packages/eslint-plugin-pf-codemods/lib/rules/pagination-removed-variant.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = {
1212
const attribute = node.attributes.find(node => node.name && node.name.name === 'variant');
1313
if (attribute) {
1414
const attributeValue = context.getSourceCode().getText(attribute.value);
15-
if (['"left"', '"right"'].includes(attributeValue))
15+
if (/left|right/.test(attributeValue))
1616
context.report({
1717
node,
1818
message: `variant ${attributeValue} has been removed from ${node.name.name}`,

packages/eslint-plugin-pf-codemods/test/rules/pagination-removed-variant.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ ruleTester.run("pagination-removed-variant", rule, {
2626
message: `variant "right" has been removed from Pagination`,
2727
type: "JSXOpeningElement",
2828
}]
29+
},
30+
{
31+
code: `import { Pagination, PaginationVariant } from '@patternfly/react-core'; <Pagination variant={PaginationVariant.right} />`,
32+
output: `import { Pagination, PaginationVariant } from '@patternfly/react-core'; <Pagination />`,
33+
errors: [{
34+
message: `variant {PaginationVariant.right} has been removed from Pagination`,
35+
type: "JSXOpeningElement",
36+
}]
2937
}
3038
]
3139
});

packages/eslint-plugin-pf-codemods/test/rules/progress-remove-info-variant.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,13 @@ ruleTester.run("progress-remove-info-variant", rule, {
2020
type: "JSXOpeningElement",
2121
}]
2222
},
23+
{
24+
code: `import { Progress, ProgressVariant } from '@patternfly/react-core'; <Progress variant={ProgressVariant.info} />`,
25+
output: `import { Progress, ProgressVariant } from '@patternfly/react-core'; <Progress />`,
26+
errors: [{
27+
message: `info variant which adds no styling has been removed for Progress. Don't pass this prop`,
28+
type: "JSXOpeningElement",
29+
}]
30+
},
2331
]
2432
});

0 commit comments

Comments
 (0)