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
1 change: 1 addition & 0 deletions packages/eslint-plugin-pf-codemods/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const { getPackageImports } = require('../helpers');

const renames = {
Copy link
Contributor

Choose a reason for hiding this comment

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

This could just be a list, but since Boolean('REMOVE') == true, you're okay :)

'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, '');
}
});
});
}
}
};
}
};
Original file line number Diff line number Diff line change
@@ -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'; <Wizard />`,
},
{
// No @patternfly/react-core import
code: `<Wizard />`,
}
],
invalid: [
{
code: `import { Wizard } from '@patternfly/react-core'; <Wizard isCompactNav />`,
output: `import { Wizard } from '@patternfly/react-core'; <Wizard />`,
errors: [{
message: `isCompactNav prop for Wizard has been removed`,
type: "JSXOpeningElement",
}]
},
{
code: `import { Wizard } from '@patternfly/react-core'; <Wizard inPage />`,
output: `import { Wizard } from '@patternfly/react-core'; <Wizard />`,
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'; <Wizard isFullHeight />`,
output: `import { Wizard } from '@patternfly/react-core'; <Wizard />`,
errors: [{
message: `isFullHeight prop for Wizard has been removed`,
type: "JSXOpeningElement",
}]
},
{
code: `import { Wizard } from '@patternfly/react-core'; <Wizard isFullWidth />`,
output: `import { Wizard } from '@patternfly/react-core'; <Wizard />`,
errors: [{
message: `isFullWidth prop for Wizard has been removed`,
type: "JSXOpeningElement",
}]
}
]
});