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
2 changes: 1 addition & 1 deletion generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = {
if (attribute) {
context.report({
node,
message: 'YOUR MESSAGE HERE',
message: 'YOUR_MESSAGE_HERE',
fix(fixer) {
return fixer.replaceText(attribute, '');
}
Expand Down
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 @@ -32,6 +32,7 @@ const rules = {
"rename-noPadding": require('./lib/rules/rename-noPadding'),
"tab-title-text": require('./lib/rules/tab-title-text'),
"table-removed-transforms": require('./lib/rules/table-removed-transforms'),
"select-rename-checkbox": require('./lib/rules/select-rename-checkbox'),
};

module.exports = {
Expand Down
5 changes: 3 additions & 2 deletions packages/eslint-plugin-pf-codemods/lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ function renameProp(components, propMap, message, replaceAttribute) {

return imports.length === 0 ? {} : {
JSXOpeningElement(node) {
if (imports.map(imp => imp.local.name).includes(node.name.name)) {
const imp = imports.find(imp => imp.local.name === node.name.name);
if (imp) {
node.attributes
.filter(node => Object.keys(propMap).includes(node.name.name))
.filter(node => Object.keys(propMap).includes(imp.imported.name))
.forEach(attribute => {
const newName = propMap[attribute.name.name];
context.report({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const { getPackageImports } = require('../helpers');

// https://github.com/patternfly/patternfly-react/pull/3945
// CheckboxSelectOption -> SelectOption
// CheckboxSelect -> Select variant="checkbox"
module.exports = {
create: function(context) {
const imports = getPackageImports(context, '@patternfly/react-core')
.filter(specifier => ['CheckboxSelect', 'CheckboxSelectOption'].includes(specifier.imported.name));

return imports.length === 0 ? {} : {
JSXIdentifier(node) {
const imp = imports.find(imp => imp.local.name === node.name);
if (imp) {
if (imp.imported.name === 'CheckboxSelect') {
context.report({
node,
message: `${node.name} has been removed. Use <Select variant="checkbox"> instead.`,
fix(fixer) {
const replacement = node.parent.type === 'JSXOpeningElement' ? 'Select variant="checkbox"' : 'Select';
return fixer.replaceText(node, replacement);
}
});
}
else if (imp.imported.name === 'CheckboxSelectOption') {
context.report({
node,
message: `${node.name} has been removed. Use <SelectOption> instead.`,
fix(fixer) {
return fixer.replaceText(node, 'SelectOption');
}
});
}
}
}
};
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
const ruleTester = require('./ruletester');
const rule = require('../../lib/rules/select-rename-checkbox');

ruleTester.run("select-rename-checkbox", rule, {
valid: [
{
code: `import { CheckboxSelect, CheckboxSelectOption } from '@patternfly/react-core';
<Select variant="checkbox">
<SelectOption>option1</SelectOption>
<SelectOption>option2</SelectOption>
</Select>`,
}
],
invalid: [
{
code: `import { CheckboxSelect } from '@patternfly/react-core'; <CheckboxSelect>{items}</CheckboxSelect>`,
output: `import { CheckboxSelect } from '@patternfly/react-core'; <Select variant="checkbox">{items}</Select>`,
errors: [
{
message: `CheckboxSelect has been removed. Use <Select variant="checkbox"> instead.`,
type: "JSXIdentifier",
},
{
message: `CheckboxSelect has been removed. Use <Select variant="checkbox"> instead.`,
type: "JSXIdentifier",
},
]
},
{
code: `import { CheckboxSelectOption } from '@patternfly/react-core'; <CheckboxSelectOption>{items}</CheckboxSelectOption>`,
output: `import { CheckboxSelectOption } from '@patternfly/react-core'; <SelectOption>{items}</SelectOption>`,
errors: [
{
message: `CheckboxSelectOption has been removed. Use <SelectOption> instead.`,
type: "JSXIdentifier",
},
{
message: `CheckboxSelectOption has been removed. Use <SelectOption> instead.`,
type: "JSXIdentifier",
},
]
},
{
code: `import { CheckboxSelect, CheckboxSelectOption } from '@patternfly/react-core';
<CheckboxSelect>
<CheckboxSelectOption>option1</CheckboxSelectOption>
<CheckboxSelectOption>option2</CheckboxSelectOption>
</CheckboxSelect>`,
output: `import { CheckboxSelect, CheckboxSelectOption } from '@patternfly/react-core';
<Select variant="checkbox">
<SelectOption>option1</SelectOption>
<SelectOption>option2</SelectOption>
</Select>`,
errors: [
{
message: 'CheckboxSelect has been removed. Use <Select variant="checkbox"> instead.',
type: 'JSXIdentifier'
},
{
message: 'CheckboxSelectOption has been removed. Use <SelectOption> instead.',
type: 'JSXIdentifier'
},
{
message: 'CheckboxSelectOption has been removed. Use <SelectOption> instead.',
type: 'JSXIdentifier'
},
{
message: 'CheckboxSelectOption has been removed. Use <SelectOption> instead.',
type: 'JSXIdentifier'
},
{
message: 'CheckboxSelectOption has been removed. Use <SelectOption> instead.',
type: 'JSXIdentifier'
},
{
message: 'CheckboxSelect has been removed. Use <Select variant="checkbox"> instead.',
type: 'JSXIdentifier'
}
]
},
]
});