const ruleTester = require("../../ruletester"); import * as rule from "./button-moveIcons-icon-prop"; ruleTester.run("button-moveIcons-icon-prop", rule, { valid: [ { code: `Some icon`, }, { code: `import { Button } from '@patternfly/react-core'; Some icon} />`, }, // with non PF Icon child { code: `import { Button } from '@patternfly/react-core'; Some icon`, }, ], invalid: [ { code: `import { Button } from '@patternfly/react-core'; const icon = Some icon; {icon}`, output: `import { Button } from '@patternfly/react-core'; const icon = Some icon; `, errors: [ { message: `Icons must now be passed to the \`icon\` prop of Button instead of as children. If you are passing anything other than an icon as children, ignore this rule when running fixes.`, type: "JSXElement", }, ], }, { code: `import { Button } from '@patternfly/react-core'; Some icon`, output: `import { Button } from '@patternfly/react-core'; Some icon} variant="plain" />`, errors: [ { message: `Icons must now be passed to the \`icon\` prop of Button instead of as children. If you are passing anything other than an icon as children, ignore this rule when running fixes.`, type: "JSXElement", }, ], }, { code: `import { Button, ButtonVariant } from '@patternfly/react-core'; Some icon`, output: `import { Button, ButtonVariant } from '@patternfly/react-core'; Some icon} variant={ButtonVariant.plain} />`, errors: [ { message: `Icons must now be passed to the \`icon\` prop of Button instead of as children. If you are passing anything other than an icon as children, ignore this rule when running fixes.`, type: "JSXElement", }, ], }, { code: `import { Button as CustomThing } from '@patternfly/react-core'; Some icon`, output: `import { Button as CustomThing } from '@patternfly/react-core'; Some icon} variant="plain" />`, errors: [ { message: `Icons must now be passed to the \`icon\` prop of Button instead of as children. If you are passing anything other than an icon as children, ignore this rule when running fixes.`, type: "JSXElement", }, ], }, { code: `import { Button } from '@patternfly/react-core/dist/esm/components/Button/index.js'; Some icon`, output: `import { Button } from '@patternfly/react-core/dist/esm/components/Button/index.js'; Some icon} variant="plain" />`, errors: [ { message: `Icons must now be passed to the \`icon\` prop of Button instead of as children. If you are passing anything other than an icon as children, ignore this rule when running fixes.`, type: "JSXElement", }, ], }, { code: `import { Button } from '@patternfly/react-core/dist/js/components/Button/index.js'; Some icon`, output: `import { Button } from '@patternfly/react-core/dist/js/components/Button/index.js'; Some icon} variant="plain" />`, errors: [ { message: `Icons must now be passed to the \`icon\` prop of Button instead of as children. If you are passing anything other than an icon as children, ignore this rule when running fixes.`, type: "JSXElement", }, ], }, { code: `import { Button } from '@patternfly/react-core/dist/dynamic/components/Button/index.js'; Some icon`, output: `import { Button } from '@patternfly/react-core/dist/dynamic/components/Button/index.js'; Some icon} variant="plain" />`, errors: [ { message: `Icons must now be passed to the \`icon\` prop of Button instead of as children. If you are passing anything other than an icon as children, ignore this rule when running fixes.`, type: "JSXElement", }, ], }, // with Icon component child { code: `import { Button, Icon } from '@patternfly/react-core'; Some icon`, output: `import { Button, Icon } from '@patternfly/react-core'; Some icon}>`, errors: [ { message: `Icons must now be passed to the \`icon\` prop of Button instead of as children. If you are passing anything other than an icon as children, ignore this rule when running fixes.`, type: "JSXElement", }, ], }, // with Icon component child (aliased) { code: `import { Button, Icon as PFIcon } from '@patternfly/react-core'; Some icon`, output: `import { Button, Icon as PFIcon } from '@patternfly/react-core'; Some icon}>`, errors: [ { message: `Icons must now be passed to the \`icon\` prop of Button instead of as children. If you are passing anything other than an icon as children, ignore this rule when running fixes.`, type: "JSXElement", }, ], }, // with react-icons icon child { code: `import { Button } from '@patternfly/react-core'; import { SomeIcon } from "@patternfly/react-icons"; `, output: `import { Button } from '@patternfly/react-core'; import { SomeIcon } from "@patternfly/react-icons"; }>`, errors: [ { message: `Icons must now be passed to the \`icon\` prop of Button instead of as children. If you are passing anything other than an icon as children, ignore this rule when running fixes.`, type: "JSXElement", }, ], }, // with react-icons icon child and another child { code: `import { Button } from '@patternfly/react-core'; import { SomeIcon } from "@patternfly/react-icons"; Text`, output: `import { Button } from '@patternfly/react-core'; import { SomeIcon } from "@patternfly/react-icons"; }>Text`, errors: [ { message: `Icons must now be passed to the \`icon\` prop of Button instead of as children. If you are passing anything other than an icon as children, ignore this rule when running fixes.`, type: "JSXElement", }, ], }, // with children prop { code: `import { Button } from '@patternfly/react-core'; Some icon} />`, output: `import { Button } from '@patternfly/react-core'; Some icon} variant="plain" />`, errors: [ { message: `Icons must now be passed to the \`icon\` prop of Button instead of as children. If you are passing anything other than an icon as children, ignore this rule when running fixes.`, type: "JSXElement", }, ], }, // with react-icons icon child in children prop (inside JSXFragment) { code: `import { Button } from '@patternfly/react-core'; import { SomeIcon } from "@patternfly/react-icons"; Text >} />`, output: `import { Button } from '@patternfly/react-core'; import { SomeIcon } from "@patternfly/react-icons"; } children={<>Text >} />`, errors: [ { message: `Icons must now be passed to the \`icon\` prop of Button instead of as children. If you are passing anything other than an icon as children, ignore this rule when running fixes.`, type: "JSXElement", }, ], }, // with react-icons icon child in children prop (inside JSXElement) { code: `import { Button } from '@patternfly/react-core'; import { SomeIcon } from "@patternfly/react-icons"; Text } />`, output: `import { Button } from '@patternfly/react-core'; import { SomeIcon } from "@patternfly/react-icons"; } children={Text } />`, errors: [ { message: `Icons must now be passed to the \`icon\` prop of Button instead of as children. If you are passing anything other than an icon as children, ignore this rule when running fixes.`, type: "JSXElement", }, ], }, ], });