diff --git a/packages/eslint-plugin-pf-codemods/index.js b/packages/eslint-plugin-pf-codemods/index.js index 5d78871c4..85fd5ccf9 100644 --- a/packages/eslint-plugin-pf-codemods/index.js +++ b/packages/eslint-plugin-pf-codemods/index.js @@ -13,6 +13,7 @@ const rules = { "title-size": require('./lib/rules/title-size'), "wizard-text": require('./lib/rules/wizard-text'), "wizard-rename-hasBodyPadding": require('./lib/rules/wizard-rename-hasBodyPadding'), + "wizard-remove-props": require('./lib/rules/wizard-remove-props'), }; module.exports = { diff --git a/packages/eslint-plugin-pf-codemods/lib/rules/wizard-remove-props.js b/packages/eslint-plugin-pf-codemods/lib/rules/wizard-remove-props.js new file mode 100644 index 000000000..cbdf097d1 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/lib/rules/wizard-remove-props.js @@ -0,0 +1,35 @@ +const { getPackageImports } = require('../helpers'); + +const renames = { + 'isCompactNav': 'REMOVE', + 'inPage': 'REMOVE', + 'isFullWidth': 'REMOVE', + 'isFullHeight': 'REMOVE' +}; + +// https://github.com/patternfly/patternfly-react/pull/4142 +// https://github.com/patternfly/patternfly-react/pull/4116 +module.exports = { + create: function(context) { + const imports = getPackageImports(context, '@patternfly/react-core') + .filter(specifier => specifier.imported.name === 'Wizard'); + + return !imports ? {} : { + JSXOpeningElement(node) { + if (imports.map(imp => imp.local.name).includes(node.name.name)) { + node.attributes + .filter(attribute => renames[attribute.name.name]) + .forEach(removedWizardProp => { + context.report({ + node, + message: `${removedWizardProp.name.name} prop for ${node.name.name} has been removed`, + fix(fixer) { + return fixer.replaceText(removedWizardProp, ''); + } + }); + }); + } + } + }; + } +}; diff --git a/packages/eslint-plugin-pf-codemods/test/rules/wizard-remove-props.js b/packages/eslint-plugin-pf-codemods/test/rules/wizard-remove-props.js new file mode 100644 index 000000000..8e45965a2 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/test/rules/wizard-remove-props.js @@ -0,0 +1,50 @@ +const ruleTester = require('./ruletester'); +const rule = require('../../lib/rules/wizard-remove-props'); + +ruleTester.run("wizard-remove-props", rule, { + valid: [ + { + code: `import { Wizard } from '@patternfly/react-core'; `, + }, + { + // No @patternfly/react-core import + code: ``, + } + ], + invalid: [ + { + code: `import { Wizard } from '@patternfly/react-core'; `, + output: `import { Wizard } from '@patternfly/react-core'; `, + errors: [{ + message: `isCompactNav prop for Wizard has been removed`, + type: "JSXOpeningElement", + }] + }, + { + code: `import { Wizard } from '@patternfly/react-core'; `, + output: `import { Wizard } from '@patternfly/react-core'; `, + errors: [{ + message: `inPage prop for Wizard has been removed. + By default the Wizard will be displayed in page, filling its parent container. + If the consumer passes a managed isOpen flag, then the Wizard will be displayed in a modal.`, + type: "JSXOpeningElement", + }] + }, + { + code: `import { Wizard } from '@patternfly/react-core'; `, + output: `import { Wizard } from '@patternfly/react-core'; `, + errors: [{ + message: `isFullHeight prop for Wizard has been removed`, + type: "JSXOpeningElement", + }] + }, + { + code: `import { Wizard } from '@patternfly/react-core'; `, + output: `import { Wizard } from '@patternfly/react-core'; `, + errors: [{ + message: `isFullWidth prop for Wizard has been removed`, + type: "JSXOpeningElement", + }] + } + ] +});