Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
33 changes: 21 additions & 12 deletions packages/eslint-plugin-pf-codemods/index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
const createListOfRules = (version) => {
const rules = {};
require('glob').sync(`./packages/eslint-plugin-pf-codemods/lib/rules/v${version}/*.js`).forEach( function( file ) {
const ruleName = /.*\/([^.]+)/.exec(file)[1];
rules[ruleName] = require(`./lib/rules/v${version}/${ruleName}`);
});
require("glob")
.sync(`./packages/eslint-plugin-pf-codemods/lib/rules/v${version}/*.js`)
.forEach(function (file) {
const ruleName = /.*\/([^.]+)/.exec(file)[1];
rules[ruleName] = require(`./lib/rules/v${version}/${ruleName}`);
});
return rules;
}
};

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", "card-warn-component", "horizontalSubnav-ariaLabel", "tabs-warn-children-type-changed", "wizard-warn-button-order"]
const warningRules = [
"applicationLauncher-warn-input",
"card-warn-component",
"horizontalSubnav-ariaLabel",
"react-dropzone-warn-upgrade",
"tabs-warn-children-type-changed",
"wizard-warn-button-order",
];

const createRules = (rules) => {
return Object.keys(rules).reduce((acc, rule) => {
const severity = warningRules.includes(rule) ? "warn" : "error"
const severity = warningRules.includes(rule) ? "warn" : "error";
acc[`@patternfly/pf-codemods/${rule}`] = severity;
return acc;
}, {})
}
}, {});
};

const mappedRules = {...createRules(v5rules), ...createRules(v4rules)};
const mappedRules = { ...createRules(v5rules), ...createRules(v4rules) };

module.exports = {
configs: {
Expand All @@ -44,6 +53,6 @@ module.exports = {
rules: mappedRules,
},
},
rules: {...v5rules, ...v4rules},
ruleVersionMapping: {"v4": Object.keys(v4rules), "v5": Object.keys(v5rules)}
rules: { ...v5rules, ...v4rules },
ruleVersionMapping: { v4: Object.keys(v4rules), v5: Object.keys(v5rules) },
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// https://github.com/patternfly/patternfly-react/pull/7926
module.exports = {
meta: {},
create: function (context) {
return {
ImportDeclaration(node) {
const importsWithDropzone = node.specifiers.find(
(specifier) =>
(["FileUpload", "MultipleFileUpload"].includes(
specifier.imported.name
) &&
node.source.value === "@patternfly/react-core") ||
(specifier.imported.name === "CodeEditor" &&
node.source.value === "@patternfly/react-code-editor")
);

if (importsWithDropzone) {
context.report({
node,
message: `The react-dropzone dependency used within ${importsWithDropzone.imported.name} has been updated from version 9 to version 14.`,
});
}
},
};
},
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const { getPackageImports } = require("../../helpers");

// https://github.com/patternfly/patternfly-react/pull/8409
module.exports = {
create: function (context) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const ruleTester = require("../../ruletester");
const rule = require("../../../lib/rules/v5/react-dropzone-warn-upgrade");

ruleTester.run("react-dropzone-warn-upgrade", rule, {
valid: [],
invalid: [
{
code: `import { FileUpload } from '@patternfly/react-core';`,
output: `import { FileUpload } from '@patternfly/react-core';`,
errors: [
{
message: `The react-dropzone dependency used within FileUpload has been updated from version 9 to version 14.`,
type: "ImportDeclaration",
},
],
},
{
code: `import { MultipleFileUpload } from '@patternfly/react-core';`,
output: `import { MultipleFileUpload } from '@patternfly/react-core';`,
errors: [
{
message: `The react-dropzone dependency used within MultipleFileUpload has been updated from version 9 to version 14.`,
type: "ImportDeclaration",
},
],
},
{
code: `import { CodeEditor } from '@patternfly/react-code-editor';`,
output: `import { CodeEditor } from '@patternfly/react-code-editor';`,
errors: [
{
message: `The react-dropzone dependency used within CodeEditor has been updated from version 9 to version 14.`,
type: "ImportDeclaration",
},
],
},
],
});
28 changes: 16 additions & 12 deletions packages/pf-codemods/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,10 @@ Out:
/>
```

### react-dropzone-warn-upgrade [(#7926)](// https://github.com/patternfly/patternfly-react/pull/7926)

The `react-dropzone` dependency used with FileUpload, MultipleFileUpload, and CodeEditor has been updated from version 9 to version 14.
Copy link
Contributor

Choose a reason for hiding this comment

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

What might a consumer need to do with this change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

From the PR itself, other than updating the version it looks like there were some type updates. Other than possibly mentioning those in the warning message, we could just state that the version bump may require additional breaking changes to be made (though it's a bit generic)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Though part of that may be resolved with #142

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm, I wonder if this and a PR for #142 are both needed 🤔

Copy link
Contributor

@gitdallas gitdallas Jan 25, 2023

Choose a reason for hiding this comment

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

right... i wonder if the language from this can be merged into 142 (if we still want to talk about version numbers)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We could update the output warning here so that if FileUpload/MultipleFileUpload are imported, warn that "As part of the react-dropzone dependency upgrade from version 9 to 14, the type of X prop has been changed to Y...." Code Editor would just get a warning about the version bump.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah that would make sense to me. Want me to do that under a followup?


### remove-removeFindDomNode [(#8371)](https://github.com/patternfly/patternfly-react/pull/8371) [(#8316)](https://github.com/patternfly/patternfly-react/pull/8316)

We've removed the `removeFindDomNode` property as it is now the default behavior. The affected components are as follows: ApplicationLauncher, ClipboardCopy, ContextSelector, Dropdown, NavItem, OptionsMenu, Popover, SearchInput, Select, OverflowTab, Timepicker, Tooltip, Truncate.
Expand Down Expand Up @@ -458,58 +462,58 @@ We've removed the deprecated `ToggleMenuBaseProps` interface.

We've updated the default value of the `getResizeObserver` helper function's third parameter, `useRequestAnimationFrame`. This rule will only provide two suggestions detailing when to pass which boolean into this parameter.

### tableComposable-remove-hasSelectableRowCaption [(#8352)](https://github.com/patternfly/patternfly-react/pull/8352)
### simpleList-remove-isCurrent [(#8132)](https://github.com/patternfly/patternfly-react/pull/8132)

We've removed the deprecated `hasSelectableRowCaption` prop.
We've removed the deprecated the `isCurrent` prop. This rule wil replace it with `isActive`.

#### Examples

In:

```jsx
<TableComposable hasSelectableRowCaption />
<SimpleList isCurrent />
```

Out:

```jsx
<TableComposable />
<SimpleList isActive />
```

### simpleList-remove-isCurrent [(#8132)](https://github.com/patternfly/patternfly-react/pull/8132)
### spinner-svg-default [(#8183)](https://github.com/patternfly/patternfly-react/pull/8183)

We've removed the deprecated the `isCurrent` prop. This rule wil replace it with `isActive`.
We've updated the Spinner to default to an svg, so the `isSVG` property is no longer required.

#### Examples

In:

```jsx
<SimpleList isCurrent />
<Spinner isSVG />
```

Out:

```jsx
<SimpleList isActive />
<Spinner />
```

### spinner-svg-default [(#8183)](https://github.com/patternfly/patternfly-react/pull/8183)
### tableComposable-remove-hasSelectableRowCaption [(#8352)](https://github.com/patternfly/patternfly-react/pull/8352)

We've updated the Spinner to default to an svg, so the `isSVG` property is no longer required.
We've removed the deprecated `hasSelectableRowCaption` prop.

#### Examples

In:

```jsx
<Spinner isSVG />
<TableComposable hasSelectableRowCaption />
```

Out:

```jsx
<Spinner />
<TableComposable />
```

### tabs-rename-hasBorderBottom [(#8517)](https://github.com/patternfly/patternfly-react/pull/8517)
Expand Down
11 changes: 7 additions & 4 deletions test/test.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { AccordionExpandableContent } from "@patternfly/react-core";
import { ApplicationLauncher } from "@patternfly/react-core";
import { Card } from "@patternfly/react-core";
import { CodeEditor } from "@patternfly/react-code-editor";
import { DropdownToggle, Toggle } from "@patternfly/react-core";
import { FileUpload } from "@patternfly/react-core";
import { KEY_CODES } from "@patternfly/react-core";
import { MultipleFileUpload } 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";

<>
<DropdownToggle isPrimary />
<Nav variant='horizontal-subnav' />;
<Toggle isPrimary />
</>
<DropdownToggle isPrimary />
<Nav variant='horizontal-subnav' />;
<Toggle isPrimary />
</>;