Skip to content

Commit 148cd7f

Browse files
committed
🔨 Renames JSX utils to exclude ByName
1 parent a9b7bef commit 148cd7f

File tree

27 files changed

+225
-247
lines changed

27 files changed

+225
-247
lines changed

.changeset/eleven-elephants-look.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@codeshift/utils': patch
3+
---
4+
5+
Removes ByName suffix from JSX util methods

community/@atlaskit__avatar/18.0.0/transform.ts

Lines changed: 60 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
getDefaultImportSpecifierName,
1212
getImportSpecifierName,
1313
getImportDeclaration,
14-
getJSXAttributesByName,
14+
getJSXAttributes,
1515
} from '@codeshift/utils';
1616

1717
function updateAvatarProps(j: core.JSCodeshift, source: ReturnType<typeof j>) {
@@ -24,15 +24,15 @@ function updateAvatarProps(j: core.JSCodeshift, source: ReturnType<typeof j>) {
2424
if (!defaultSpecifier) return;
2525

2626
source.findJSXElements(defaultSpecifier).forEach(element => {
27-
getJSXAttributesByName(j, element, 'isHover').remove();
28-
getJSXAttributesByName(j, element, 'isActive').remove();
29-
getJSXAttributesByName(j, element, 'isFocus').remove();
30-
getJSXAttributesByName(j, element, 'isSelected').remove();
31-
getJSXAttributesByName(j, element, 'theme').remove();
27+
getJSXAttributes(j, element, 'isHover').remove();
28+
getJSXAttributes(j, element, 'isActive').remove();
29+
getJSXAttributes(j, element, 'isFocus').remove();
30+
getJSXAttributes(j, element, 'isSelected').remove();
31+
getJSXAttributes(j, element, 'theme').remove();
3232

33-
const nameAttributes = getJSXAttributesByName(j, element, 'name');
33+
const nameAttributes = getJSXAttributes(j, element, 'name');
3434
const name = nameAttributes.length && nameAttributes.get();
35-
const enableTooltipAttributes = getJSXAttributesByName(
35+
const enableTooltipAttributes = getJSXAttributes(
3636
j,
3737
element,
3838
'enableTooltip',
@@ -121,61 +121,59 @@ function updateAvatarItemProps(
121121
if (!importSpecifier) return;
122122

123123
source.findJSXElements(importSpecifier).forEach(element => {
124-
getJSXAttributesByName(j, element, 'isHover').remove();
125-
getJSXAttributesByName(j, element, 'isActive').remove();
126-
getJSXAttributesByName(j, element, 'isFocus').remove();
127-
getJSXAttributesByName(j, element, 'isSelected').remove();
128-
getJSXAttributesByName(j, element, 'theme').remove();
129-
getJSXAttributesByName(j, element, 'enableTextTruncate').forEach(
130-
attribute => {
131-
// Change the prop name to isTruncationDisabled
132-
j(attribute)
133-
.find(j.JSXIdentifier)
134-
.replaceWith(j.jsxIdentifier('isTruncationDisabled'));
135-
136-
// Remove if enableTextTruncate was true or given no value (ie true)
137-
j(attribute)
138-
.filter(attr => attr.node.value == null)
139-
.remove();
140-
141-
j(attribute)
142-
.filter(attr => {
143-
return !!j(attr)
124+
getJSXAttributes(j, element, 'isHover').remove();
125+
getJSXAttributes(j, element, 'isActive').remove();
126+
getJSXAttributes(j, element, 'isFocus').remove();
127+
getJSXAttributes(j, element, 'isSelected').remove();
128+
getJSXAttributes(j, element, 'theme').remove();
129+
getJSXAttributes(j, element, 'enableTextTruncate').forEach(attribute => {
130+
// Change the prop name to isTruncationDisabled
131+
j(attribute)
132+
.find(j.JSXIdentifier)
133+
.replaceWith(j.jsxIdentifier('isTruncationDisabled'));
134+
135+
// Remove if enableTextTruncate was true or given no value (ie true)
136+
j(attribute)
137+
.filter(attr => attr.node.value == null)
138+
.remove();
139+
140+
j(attribute)
141+
.filter(attr => {
142+
return !!j(attr)
143+
.find(j.JSXExpressionContainer)
144+
.find(j.BooleanLiteral)
145+
.filter(literal => literal.node.value).length;
146+
})
147+
.remove();
148+
149+
// if `enableTextTruncate` value is negative we can change it to 'true'
150+
j(attribute)
151+
.filter(
152+
attr =>
153+
!!j(attr)
144154
.find(j.JSXExpressionContainer)
145-
.find(j.BooleanLiteral)
146-
.filter(literal => literal.node.value).length;
147-
})
148-
.remove();
149-
150-
// if `enableTextTruncate` value is negative we can change it to 'true'
151-
j(attribute)
152-
.filter(
153-
attr =>
154-
!!j(attr)
155-
.find(j.JSXExpressionContainer)
156-
.filter(
157-
expression =>
158-
j(expression)
159-
.find(j.BooleanLiteral)
160-
.filter(literal => !literal.node.value).length > 0,
161-
).length,
162-
)
163-
.replaceWith(j.jsxAttribute(j.jsxIdentifier('isTruncationDisabled')));
164-
165-
// if `enableTextTruncate` was an expression, negate it
166-
j(attribute)
167-
.find(j.JSXExpressionContainer)
168-
.filter(container => j(container).find(j.BooleanLiteral).length === 0)
169-
.forEach(container => {
170-
j(container).replaceWith(
171-
j.jsxExpressionContainer(
172-
//@ts-ignore
173-
j.unaryExpression('!', container.node.expression),
174-
),
175-
);
176-
});
177-
},
178-
);
155+
.filter(
156+
expression =>
157+
j(expression)
158+
.find(j.BooleanLiteral)
159+
.filter(literal => !literal.node.value).length > 0,
160+
).length,
161+
)
162+
.replaceWith(j.jsxAttribute(j.jsxIdentifier('isTruncationDisabled')));
163+
164+
// if `enableTextTruncate` was an expression, negate it
165+
j(attribute)
166+
.find(j.JSXExpressionContainer)
167+
.filter(container => j(container).find(j.BooleanLiteral).length === 0)
168+
.forEach(container => {
169+
j(container).replaceWith(
170+
j.jsxExpressionContainer(
171+
//@ts-ignore
172+
j.unaryExpression('!', container.node.expression),
173+
),
174+
);
175+
});
176+
});
179177
});
180178
}
181179

community/@atlaskit__avatar/19.0.0/transform.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import core, { API, FileInfo, Options } from 'jscodeshift';
22

33
import {
44
getImportSpecifierName,
5-
getJSXAttributesByName,
5+
getJSXAttributes,
66
hasImportDeclaration,
77
getDefaultImportSpecifierName,
88
} from '@codeshift/utils';
@@ -13,7 +13,7 @@ function wrapChildrenProp(
1313
specifier: string,
1414
) {
1515
source.findJSXElements(specifier).forEach(element => {
16-
const componentProp = getJSXAttributesByName(j, element, 'component').get();
16+
const componentProp = getJSXAttributes(j, element, 'component').get();
1717
const componentName = j(componentProp)
1818
.find(j.JSXExpressionContainer)
1919
.find(j.Expression)

community/@atlaskit__breadcrumbs/11.0.0/motions/remove-has-separator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import core, { ASTPath, Collection, Node } from 'jscodeshift';
22
import {
33
insertCommentToStartOfFile,
4-
getJSXAttributesByName,
4+
getJSXAttributes,
55
getImportSpecifierName,
66
} from '@codeshift/utils';
77

@@ -21,7 +21,7 @@ const createRemoveFuncFor = (
2121
if (predicate(j, element) && comment) {
2222
insertCommentToStartOfFile(j, source, comment);
2323
} else {
24-
getJSXAttributesByName(j, element, prop).forEach(attribute => {
24+
getJSXAttributes(j, element, prop).forEach(attribute => {
2525
j(attribute).remove();
2626
});
2727
}

community/@atlaskit__button/15.1.1/transform.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const relevantEntryPoints = [
1919
'@atlaskit/button/custom-theme-button',
2020
];
2121

22-
function getJSXAttributesByName(
22+
function getJSXAttributes(
2323
j: core.JSCodeshift,
2424
element: JSXElement,
2525
attributeName: string,
@@ -62,13 +62,13 @@ function renameProp(
6262
attributeTo: string,
6363
) {
6464
base.findJSXElements(component).forEach(element => {
65-
const first = getJSXAttributesByName(j, element.value, attributeFrom);
65+
const first = getJSXAttributes(j, element.value, attributeFrom);
6666

6767
// not using attribute
6868
if (!first.length) return;
6969

7070
// let's check to see if they are using the to attribute
71-
const second = getJSXAttributesByName(j, element.value, attributeTo);
71+
const second = getJSXAttributes(j, element.value, attributeTo);
7272

7373
// if the attribute we are moving to already exists we are in trouble
7474
if (second.length) {

community/@atlaskit__calendar/11.0.0/motions/flatten-certain-inner-props.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import core, { Collection, Node, ObjectExpression } from 'jscodeshift';
22
import {
3-
getJSXAttributesByName,
3+
getJSXAttributes,
44
getDefaultImportSpecifierName,
55
} from '@codeshift/utils';
66

@@ -17,7 +17,7 @@ const flattenCertainChildProps = (
1717
if (!defaultSpecifier) return;
1818

1919
source.findJSXElements(defaultSpecifier).forEach(element => {
20-
getJSXAttributesByName(j, element, 'innerProps').forEach(attribute => {
20+
getJSXAttributes(j, element, 'innerProps').forEach(attribute => {
2121
j(attribute)
2222
.find(j.JSXExpressionContainer)
2323
.find(j.ObjectExpression)

community/@atlaskit__calendar/11.0.0/motions/remove-inner-props.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import core, { Collection, Node } from 'jscodeshift';
22
import {
33
insertCommentToStartOfFile,
44
getDefaultImportSpecifierName,
5-
getJSXAttributesByName,
5+
getJSXAttributes,
66
} from '@codeshift/utils';
77

88
const removeInnerProps = (j: core.JSCodeshift, source: Collection<Node>) => {
@@ -15,7 +15,7 @@ const removeInnerProps = (j: core.JSCodeshift, source: Collection<Node>) => {
1515
if (!defaultSpecifier) return;
1616

1717
source.findJSXElements(defaultSpecifier).forEach(element => {
18-
getJSXAttributesByName(j, element, 'innerProps').forEach(attribute => {
18+
getJSXAttributes(j, element, 'innerProps').forEach(attribute => {
1919
j(attribute).remove();
2020

2121
insertCommentToStartOfFile(

community/@atlaskit__checkbox/12.0.0/motions/remove-props.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import core, { Node, Collection } from 'jscodeshift';
22
import {
33
insertCommentToStartOfFile,
4-
getJSXAttributesByName,
4+
getJSXAttributes,
55
getImportSpecifierName,
66
} from '@codeshift/utils';
77

@@ -16,7 +16,7 @@ const createRemoveFuncFor = (
1616
if (!specifier) return;
1717

1818
source.findJSXElements(specifier).forEach(element => {
19-
getJSXAttributesByName(j, element, prop).forEach(attribute => {
19+
getJSXAttributes(j, element, prop).forEach(attribute => {
2020
j(attribute).remove();
2121
if (comment) {
2222
insertCommentToStartOfFile(j, source, comment);

community/@atlaskit__checkbox/12.0.0/motions/rename-inputRef.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import core, { Node, Collection } from 'jscodeshift';
2-
import {
3-
getImportSpecifierName,
4-
getJSXAttributesByName,
5-
} from '@codeshift/utils';
2+
import { getImportSpecifierName, getJSXAttributes } from '@codeshift/utils';
63

74
function hasVariableAssignment(
85
j: core.JSCodeshift,
@@ -58,7 +55,7 @@ export const renameInputRef = (
5855
if (!specifier) return;
5956

6057
source.findJSXElements(specifier).forEach(element => {
61-
getJSXAttributesByName(j, element, 'inputRef').forEach(attribute => {
58+
getJSXAttributes(j, element, 'inputRef').forEach(attribute => {
6259
j(attribute).replaceWith(
6360
j.jsxAttribute(j.jsxIdentifier('ref'), attribute.node.value),
6461
);

community/@atlaskit__menu/0.7.0/transform.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import core, { API, FileInfo, Options } from 'jscodeshift';
22
import { NodePath } from 'ast-types/lib/node-path';
33
import {
44
hasImportDeclaration,
5-
getJSXAttributesByName,
5+
getJSXAttributes,
66
getDefaultImportSpecifierName,
77
getImportSpecifierName,
88
} from '@codeshift/utils';
@@ -31,7 +31,7 @@ function updateCssFnProp(
3131
specifier: string,
3232
) {
3333
source.findJSXElements(specifier).forEach(element => {
34-
const cssFnPropCollection = getJSXAttributesByName(j, element, 'cssFn');
34+
const cssFnPropCollection = getJSXAttributes(j, element, 'cssFn');
3535

3636
// no cssProp usage for this element
3737
if (!cssFnPropCollection.length) return;

community/@atlaskit__popper/5.0.0/motions/update-modifier-prop.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import core, { Collection, JSXElement } from 'jscodeshift';
2-
import {
3-
insertCommentToStartOfFile,
4-
hasJSXAttributesByName,
5-
} from '@codeshift/utils';
2+
import { insertCommentToStartOfFile, hasJSXAttributes } from '@codeshift/utils';
63
import { NodePath } from 'ast-types/lib/node-path';
74

85
import { messageForModifierProps } from '../constants';
@@ -141,7 +138,7 @@ function isUsingProp({
141138
propName: string;
142139
}): boolean {
143140
return (
144-
hasJSXAttributesByName(j, element, propName) ||
141+
hasJSXAttributes(j, element, propName) ||
145142
isUsingThroughSpread({
146143
j,
147144
base,

community/@atlaskit__popper/5.0.0/motions/update-offset.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ import core, {
66
Literal,
77
Collection,
88
} from 'jscodeshift';
9-
import {
10-
getJSXAttributesByName,
11-
insertCommentToStartOfFile,
12-
} from '@codeshift/utils';
9+
import { getJSXAttributes, insertCommentToStartOfFile } from '@codeshift/utils';
1310

1411
import {
1512
messageForUsingExpression,
@@ -58,7 +55,7 @@ export default function updateOffset(
5855
specifier: string,
5956
) {
6057
source.findJSXElements(specifier).forEach((path: ASTPath<JSXElement>) => {
61-
const offsetExpr = getJSXAttributesByName(j, path, 'offset');
58+
const offsetExpr = getJSXAttributes(j, path, 'offset');
6259
const stringLiteral = offsetExpr.filter(
6360
attr => attr.value!.value!.type === 'StringLiteral',
6461
);

0 commit comments

Comments
 (0)