Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Tabs): added warning that the type of Tabs children is now limited #220

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,3 @@ ruleTester.run("${newRuleName}", rule, {
});
`
);

// Update index file
const ruleIndexPath = path.join(__dirname, 'packages/eslint-plugin-pf-codemods/index.js');
const ruleIndex = fs.readFileSync(ruleIndexPath, 'utf8');
fs.writeFileSync(
ruleIndexPath,
// (ab)Use fact that `rules` object is at top of file
ruleIndex.replace("};", ` "${newRuleName}": require('./lib/rules/v5/${newRuleName}'),\n};`)
);
Comment on lines -72 to -80
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed as the index file no longer needs to be manually updated with rule names.

2 changes: 1 addition & 1 deletion packages/eslint-plugin-pf-codemods/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const v5rules = createListOfRules("5");
const v4rules = createListOfRules("4");

// if you want a rule to have a severity that defaults to warning rather than error, add the rule name to the below array
const warningRules = ["applicationLauncher-warn-input", "horizontalSubnav-ariaLabel", "wizard-warn-button-order"]
const warningRules = ["applicationLauncher-warn-input", "horizontalSubnav-ariaLabel", "tabs-warn-children-type-changed", "wizard-warn-button-order"]

const createRules = (rules) => {
return Object.keys(rules).reduce((acc, rule) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const { getPackageImports } = require("../../helpers");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: could remove this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!


// https://github.com/patternfly/patternfly-react/pull/8217
module.exports = {
create: function (context) {
return {
ImportDeclaration(node) {
const TabsImport = node.specifiers.find(
(specifier) =>
specifier.imported.name === "Tabs" &&
node.source.value === "@patternfly/react-core"
);

if (TabsImport) {
context.report({
node,
message: "The children of the 'Tabs' component must now be passed a 'Tab' component or a falsy value.",
});
}
},
};
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const ruleTester = require('../../ruletester');
const rule = require('../../../lib/rules/v5/tabs-warn-children-type-changed');

ruleTester.run("tabs-warn-children-type-changed", rule, {
valid: [
{
code: `<Tabs>Child</Tabs>`,
}
],
invalid: [
{
code: `import { Tabs } from '@patternfly/react-core';`,
output: `import { Tabs } from '@patternfly/react-core';`,
errors: [{
message: `The children of the 'Tabs' component must now be passed a 'Tab' component or a falsy value.`,
type: "ImportDeclaration",
}]
},
]
});
6 changes: 6 additions & 0 deletions packages/pf-codemods/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,12 @@ Out:
<Tabs />
```

### tabs-warn-children-type-changed [(#8217)](https://github.com/patternfly/patternfly-react/pull/8217)

We've restricted the type of elements that can be passed to the `Tabs` component.

This rule will raise a warning when `Tabs` is imported in a file, even if the children passed to it are already of the appropriate type. It will not make any code changes.

### toggle-remove-isprimary [(#8179)](https://github.com/patternfly/patternfly-react/pull/8179)

We've removed the deprecated `isPrimary` prop. This rule wil replace it with the "primary" value on the `toggleVariant` prop.
Expand Down
1 change: 1 addition & 0 deletions test/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { AccordionExpandableContent } from "@patternfly/react-core";
import { ApplicationLauncher } from "@patternfly/react-core";
import { KEY_CODES } from "@patternfly/react-core";
import { Nav } from "@patternfly/react-core";
import { Tabs } from "@patternfly/react-core";
import { Wizard } from "@patternfly/react-core";
import { WizardFooter } from "@patternfly/react-core/next";

Expand Down