Skip to content

Commit df7dedc

Browse files
committed
rename tabs props
PR feedback, update output values update rule update readme add rule fix error msg fix error msg Dallas var names rule logic Co-authored-by: Dallas <dallas.nicol@gmail.com> PR feedback from Dallas, adding var names test
1 parent 1d3d34c commit df7dedc

File tree

6 files changed

+169
-0
lines changed

6 files changed

+169
-0
lines changed

packages/eslint-plugin-pf-codemods/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ const rules = {
5757
"simpleList-remove-isCurrent": require('./lib/rules/v5/simpleList-remove-isCurrent'),
5858
"spinner-svg-default": require('./lib/rules/v5/spinner-svg-default'),
5959
"tableComposable-remove-hasSelectableRowCaption": require('./lib/rules/v5/tableComposable-remove-hasSelectableRowCaption'),
60+
"tabs-rename-hasBorderBottom": require('./lib/rules/v5/tabs-rename-hasBorderBottom'),
61+
"tabs-remove-hasSecondaryBorderBottom": require('./lib/rules/v5/tabs-rename-hasSecondaryBorderBottom'),
6062
"toggle-remove-isPrimary": require('./lib/rules/v5/toggle-remove-isPrimary'),
6163
"toolbar-remove-visiblity": require('./lib/rules/v5/toolbar-remove-visiblity'),
6264
"tooltip-remove-props": require('./lib/rules/v5/tooltip-remove-props'),
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const { renameProp } = require('../../helpers');
2+
3+
// https://github.com/patternfly/patternfly-react/pull/8517
4+
module.exports = {
5+
meta: { fixable: 'code' },
6+
create: renameProp(
7+
'Tabs',
8+
{'hasSecondaryBorderBottom': ''},
9+
node => `hasSecondaryBorderBottom prop has been removed for ${node.name.name}.`
10+
),
11+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const { getPackageImports } = require('../../helpers');
2+
3+
// https://github.com/patternfly/patternfly-react/pull/8517
4+
module.exports = {
5+
meta: { fixable: 'code' },
6+
create: function(context) {
7+
const imports = getPackageImports(context, '@patternfly/react-core')
8+
.filter(specifier => specifier.imported.name === 'Tabs');
9+
const sourceCode = context.getSourceCode();
10+
11+
return imports.length == 0 ? {} : {
12+
JSXOpeningElement(node) {
13+
if (imports.map(imp => imp.local.name).includes(node.name.name)) {
14+
const attribute = node.attributes.find(node => node.name && node.name.name === 'hasBorderBottom');
15+
if (attribute) {
16+
context.report({
17+
node,
18+
message: `hasBorderBottom prop has been removed for ${node.name.name}. Use hasNoBorderBottom instead`,
19+
fix(fixer) {
20+
const attrText = attribute.value ? sourceCode.getText(attribute.value.expression) : 'true';
21+
if (['true', 'false'].includes(attrText.trim())) {
22+
return fixer.replaceText(attribute, attrText && attrText.trim() === 'false' ? 'hasNoBorderBottom' : '');
23+
}
24+
return fixer.replaceText(attribute, `hasNoBorderBottom={!(${attrText})}`)
25+
}
26+
});
27+
}
28+
}
29+
}
30+
};
31+
}
32+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const ruleTester = require("../../ruletester");
2+
const rule = require("../../../lib/rules/v5/tabs-remove-hasSecondaryBorderBottom");
3+
4+
ruleTester.run("tabs-remove-hasSecondaryBorderBottom", rule, {
5+
valid: [
6+
{
7+
code: `import { Tabs } from '@patternfly/react-core'; <Tabs />`,
8+
},
9+
{
10+
// No @patternfly/react-core import
11+
code: `<Tabs hasSecondaryBorderBottom />`,
12+
},
13+
],
14+
invalid: [
15+
{
16+
code: `import { Tabs } from '@patternfly/react-core'; <Tabs hasSecondaryBorderBottom />`,
17+
output: `import { Tabs } from '@patternfly/react-core'; <Tabs />`,
18+
errors: [
19+
{
20+
message: `hasSecondaryBorderBottom prop has been removed for Tabs.`,
21+
type: "JSXOpeningElement",
22+
},
23+
],
24+
},
25+
],
26+
});
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
const ruleTester = require("../../ruletester");
2+
const rule = require("../../../lib/rules/v5/tabs-rename-hasBorderBottom");
3+
4+
ruleTester.run("tabs-rename-hasBorderBottom", rule, {
5+
valid: [
6+
{
7+
code: `import { Tabs } from '@patternfly/react-core'; <Tabs hasNoBorderBottom />`,
8+
},
9+
{
10+
// No @patternfly/react-core import
11+
code: `<Tabs hasBorderBottom />`,
12+
},
13+
],
14+
invalid: [
15+
{
16+
code: `import { Tabs } from '@patternfly/react-core'; <Tabs hasBorderBottom />`,
17+
output: `import { Tabs } from '@patternfly/react-core'; <Tabs />`,
18+
errors: [
19+
{
20+
message: `hasBorderBottom prop has been removed for Tabs. Use hasNoBorderBottom instead`,
21+
type: "JSXOpeningElement",
22+
},
23+
],
24+
},
25+
{
26+
code: `import { Tabs } from '@patternfly/react-core'; <Tabs hasBorderBottom={true} />`,
27+
output: `import { Tabs } from '@patternfly/react-core'; <Tabs />`,
28+
errors: [
29+
{
30+
message: `hasBorderBottom prop has been removed for Tabs. Use hasNoBorderBottom instead`,
31+
type: "JSXOpeningElement",
32+
},
33+
],
34+
},
35+
{
36+
code: `import { Tabs } from '@patternfly/react-core'; <Tabs hasBorderBottom={false} />`,
37+
output: `import { Tabs } from '@patternfly/react-core'; <Tabs hasNoBorderBottom />`,
38+
errors: [
39+
{
40+
message: `hasBorderBottom prop has been removed for Tabs. Use hasNoBorderBottom instead`,
41+
type: "JSXOpeningElement",
42+
},
43+
],
44+
},
45+
{
46+
code: `import { Tabs } from '@patternfly/react-core'; <Tabs hasBorderBottom={foo && bar} />`,
47+
output: `import { Tabs } from '@patternfly/react-core'; <Tabs hasNoBorderBottom={!(foo && bar)} />`,
48+
errors: [
49+
{
50+
message: `hasBorderBottom prop has been removed for Tabs. Use hasNoBorderBottom instead`,
51+
type: "JSXOpeningElement",
52+
},
53+
],
54+
},
55+
],
56+
});

packages/pf-codemods/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,48 @@ Out:
368368
<Spinner />
369369
```
370370

371+
### tabs-rename-hasBorderBottom [(#8517)](https://github.com/patternfly/patternfly-react/pull/8517)
372+
373+
We've renamed the `hasBorderBottom` prop to `hasNoBorderBottom`.
374+
375+
#### Examples
376+
377+
In:
378+
379+
```jsx
380+
<Tabs hasBorderBottom />
381+
<Tabs hasBorderBottom={true} />
382+
<Tabs hasBorderBottom={false} />
383+
<Tabs hasBorderBottom={someVar} />
384+
```
385+
386+
Out:
387+
388+
```jsx
389+
<Tabs />
390+
<Tabs />
391+
<Tabs hasNoBorderBottom />
392+
<Tabs hasNoBorderBottom={!someVar} />
393+
```
394+
395+
### tabs-rename-hasSecondaryBorderBottom [(#8517)](https://github.com/patternfly/patternfly-react/pull/8517)
396+
397+
We've removed the deprecated `hasSecondaryBorderBottom` prop.
398+
399+
#### Examples
400+
401+
In:
402+
403+
```jsx
404+
<Tabs hasSecondaryBorderBottom />
405+
```
406+
407+
Out:
408+
409+
```jsx
410+
<Tabs />
411+
```
412+
371413
### toggle-remove-isprimary [(#8179)](https://github.com/patternfly/patternfly-react/pull/8179)
372414

373415
We've removed the deprecated `isPrimary` prop. This rule wil replace it with the "primary" value on the `toggleVariant` prop.

0 commit comments

Comments
 (0)