Skip to content

Commit

Permalink
remove Telephone eslint transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
jamigibbs committed Sep 20, 2023
1 parent 051433e commit 7ebd610
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 189 deletions.
47 changes: 0 additions & 47 deletions packages/eslint-plugin/lib/rules/prefer-web-component-library.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,6 @@ const MESSAGE =
const getPropNode = (node, propName) =>
node.openingElement.attributes.find(n => n.name.name === propName);

const telephoneTransformer = (context, node) => {
const componentName = node.openingElement.name;
const patternNode = getPropNode(node, 'pattern');
const notClickableNode = getPropNode(node, 'notClickable');
const contactNode = getPropNode(node, 'contact');
const contactValue = contactNode?.value.expression || contactNode?.value;

const stripHyphens = contactValue?.type === 'Literal';
const international =
patternNode?.value.expression?.property?.name === 'OUTSIDE_US';

context.report({
node,
message: MESSAGE,
data: {
reactComponent: componentName.name,
webComponent: 'va-telephone',
},
suggest: [
{
desc: 'Migrate component',
fix: fixer => {
// Replace the node name
// and remove the `pattern` prop if it's there
return [
fixer.replaceText(componentName, 'va-telephone'),
stripHyphens &&
fixer.replaceTextRange(
// Leave the quotes alone
[contactValue.range[0] + 1, contactValue.range[1] - 1],
contactValue.value.replace(/[^\d]/g, ''),
),
international &&
fixer.insertTextBefore(patternNode, 'international'),
patternNode && fixer.remove(patternNode),
notClickableNode &&
fixer.replaceText(notClickableNode, 'not-clickable'),
].filter(i => !!i);
},
},
],
});
};

const textInputTransformer = (context, node) => {
const componentName = node.openingElement.name;
const error = getPropNode(node, 'errorMessage');
Expand Down Expand Up @@ -374,9 +330,6 @@ module.exports = {
case 'Pagination':
paginationTransformer(context, node);
break;
case 'Telephone':
telephoneTransformer(context, node);
break;
case 'TextInput':
textInputTransformer(context, node);
break;
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@department-of-veterans-affairs/eslint-plugin",
"version": "1.10.0",
"version": "1.11.0",
"description": "ESLint plugin for va.gov projects",
"homepage": "https://github.com/department-of-veterans-affairs/veteran-facing-services-tools/tree/master/packages/eslint-plugin#readme",
"bugs": {
Expand Down
141 changes: 0 additions & 141 deletions packages/eslint-plugin/tests/lib/rules/prefer-web-component-library.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ ruleTester.run('prefer-web-component-library', rule, {
// This rule should not trigger on application components, only React components
// from the `component-library`
valid: [
// {
// code: `
// import Telephone from '../components/Telephone';
// const phone = () => (<Telephone contact={phoneContact} />)
// `,
// },
{
code: `
import Breadcrumbs from '../../components/Breadcrumbs';
Expand All @@ -50,141 +44,6 @@ ruleTester.run('prefer-web-component-library', rule, {
},
],
invalid: [
{
code: mockFile(
'Telephone',
'const phone = () => (<Telephone contact={phoneContact} />)',
),
errors: [
{
suggestions: [
{
desc: 'Migrate component',
output: mockFile(
'Telephone',
'const phone = () => (<va-telephone contact={phoneContact} />)',
),
},
],
},
],
},
{
code: mockFile(
'Telephone',
'const phone = () => (<Telephone pattern={PATTERN["3_DIGIT"]} contact={phoneContact} />)',
),
errors: [
{
suggestions: [
{
desc: 'Migrate component',
// There is an extra space which would get removed on an autosave format
output: mockFile(
'Telephone',
'const phone = () => (<va-telephone contact={phoneContact} />)',
),
},
],
},
],
},
{
code: mockFile(
'Telephone',
'const phone = () => (<Telephone pattern={PATTERN.OUTSIDE_US} contact={phoneContact} />)',
),
errors: [
{
suggestions: [
{
desc: 'Migrate component',
output: mockFile(
'Telephone',
'const phone = () => (<va-telephone international contact={phoneContact} />)',
),
},
],
},
],
},
{
code: mockFile(
'Telephone',
'const phone = () => (<Telephone pattern="###" contact={phoneContact} />)',
),
errors: [
{
suggestions: [
{
desc: 'Migrate component',
output: mockFile(
'Telephone',
'const phone = () => (<va-telephone contact={phoneContact} />)',
),
},
],
},
],
},

{
code: mockFile(
'Telephone',
'const phone = () => (<Telephone contact={"800-456-5432"} />)',
),
errors: [
{
suggestions: [
{
desc: 'Migrate component',
output: mockFile(
'Telephone',
'const phone = () => (<va-telephone contact={"8004565432"} />)',
),
},
],
},
],
},
{
code: mockFile(
'Telephone',
'const phone = () => (<Telephone contact="800-456-5432" />)',
),
errors: [
{
suggestions: [
{
desc: 'Migrate component',
output: mockFile(
'Telephone',
'const phone = () => (<va-telephone contact="8004565432" />)',
),
},
],
},
],
},
{
code: mockFile(
'Telephone',
'const phone = () => (<Telephone notClickable contact={myContact} />)',
),
errors: [
{
suggestions: [
{
desc: 'Migrate component',
output: mockFile(
'Telephone',
'const phone = () => (<va-telephone not-clickable contact={myContact} />)',
),
},
],
},
],
},
{
code: mockFile(
'Breadcrumbs',
Expand Down

0 comments on commit 7ebd610

Please sign in to comment.