Skip to content

Commit ce6126e

Browse files
committed
Merge branch 'main' of github.com:CodeshiftCommunity/CodeshiftCommunity into main
2 parents bb1101d + b8ce5ec commit ce6126e

File tree

32 files changed

+850
-674
lines changed

32 files changed

+850
-674
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.eslintrc.js

.eslintrc.js

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,44 @@
11
module.exports = {
2-
root: true,
3-
parser: '@typescript-eslint/parser',
4-
extends: [
5-
'plugin:@typescript-eslint/recommended',
6-
'prettier/@typescript-eslint',
7-
'plugin:prettier/recommended',
8-
],
9-
parserOptions: {
10-
ecmaVersion: 2018,
11-
sourceType: 'module',
12-
project: './tsconfig.json',
13-
ecmaFeatures: {
14-
jsx: true,
15-
},
2+
root: true,
3+
parser: '@typescript-eslint/parser',
4+
extends: [
5+
'plugin:@typescript-eslint/recommended',
6+
'plugin:prettier/recommended',
7+
'prettier',
8+
],
9+
plugins: ['prettier'],
10+
parserOptions: {
11+
ecmaVersion: 2018,
12+
sourceType: 'module',
13+
project: './tsconfig.eslint.json',
14+
ecmaFeatures: {
15+
jsx: true,
1616
},
17-
rules: {
18-
'@typescript-eslint/no-namespace': 'off',
19-
'@typescript-eslint/explicit-function-return-type': 'off',
20-
'@typescript-eslint/no-explicit-any': 'off',
21-
'@typescript-eslint/explicit-member-accessibility': 'off',
22-
'@typescript-eslint/no-non-null-assertion': 'off',
23-
'@typescript-eslint/no-parameter-properties': 'off',
24-
'@typescript-eslint/no-unused-vars': [
25-
'warn',
26-
{
27-
ignoreRestSiblings: true,
28-
},
29-
],
17+
},
18+
rules: {
19+
'@typescript-eslint/no-namespace': 'off',
20+
'@typescript-eslint/explicit-function-return-type': 'off',
21+
'@typescript-eslint/no-explicit-any': 'off',
22+
'@typescript-eslint/explicit-member-accessibility': 'off',
23+
'@typescript-eslint/no-non-null-assertion': 'off',
24+
'@typescript-eslint/no-parameter-properties': 'off',
25+
// TODO this is dangerous to allow - should re-address
26+
'@typescript-eslint/ban-ts-comment': 'off',
27+
'@typescript-eslint/no-unused-vars': [
28+
'warn',
29+
{
30+
ignoreRestSiblings: true,
31+
},
32+
],
33+
},
34+
overrides: [
35+
{
36+
files: ['*/**/*.spec.ts', '*/**/__tests__/**/*'],
37+
rules: {
38+
// This deals with import jscodeshift test utils
39+
'@typescript-eslint/no-var-requires': 'off',
40+
'@typescript-eslint/no-empty-function': 'off',
41+
},
3042
},
43+
],
3144
};

.prettierrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ module.exports = {
44
singleQuote: true,
55
printWidth: 80,
66
tabWidth: 2,
7+
arrowParens: 'avoid',
78
};

babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = api => {
1+
module.exports = (api) => {
22
api.cache(true);
33
return {
44
presets: [

community/@atlaskit__breadcrumbs/11.0.0/motions/elevate-stateless-to-default.ts

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@ import core, { ASTPath, ImportDeclaration, ImportSpecifier } from 'jscodeshift';
22

33
type Nullable<T> = T | null;
44

5-
const elevateComponentToDefault = (pkg: string, innerElementName: string) => (
6-
j: core.JSCodeshift,
7-
root: any,
8-
) => {
9-
const existingAlias: Nullable<string> =
10-
root
11-
.find(j.ImportDeclaration)
12-
.filter(
13-
(path: ASTPath<ImportDeclaration>) => path.node.source.value === pkg,
14-
)
15-
.find(j.ImportSpecifier)
16-
.nodes()
17-
.map(
18-
(specifier: ImportSpecifier): Nullable<string> => {
5+
const elevateComponentToDefault =
6+
(pkg: string, innerElementName: string) =>
7+
(j: core.JSCodeshift, root: any) => {
8+
const existingAlias: Nullable<string> =
9+
root
10+
.find(j.ImportDeclaration)
11+
.filter(
12+
(path: ASTPath<ImportDeclaration>) => path.node.source.value === pkg,
13+
)
14+
.find(j.ImportSpecifier)
15+
.nodes()
16+
.map((specifier: ImportSpecifier): Nullable<string> => {
1917
if (innerElementName !== specifier.imported.name) {
2018
return null;
2119
}
@@ -25,42 +23,42 @@ const elevateComponentToDefault = (pkg: string, innerElementName: string) => (
2523
}
2624

2725
return null;
28-
},
29-
)
30-
.filter(Boolean)[0] || null;
26+
})
27+
.filter(Boolean)[0] || null;
3128

32-
root
33-
.find(j.ImportDeclaration)
34-
.filter(
35-
(path: ASTPath<ImportDeclaration>) => path.node.source.value === pkg,
36-
)
37-
.forEach((path: ASTPath<ImportDeclaration>) => {
38-
const defaultSpecifier = (path.value.specifiers || []).filter(
39-
specifier => specifier.type === 'ImportDefaultSpecifier',
40-
);
29+
root
30+
.find(j.ImportDeclaration)
31+
.filter(
32+
(path: ASTPath<ImportDeclaration>) => path.node.source.value === pkg,
33+
)
34+
.forEach((path: ASTPath<ImportDeclaration>) => {
35+
const defaultSpecifier = (path.value.specifiers || []).filter(
36+
specifier => specifier.type === 'ImportDefaultSpecifier',
37+
);
4138

42-
let otherSpecifier = (path.value.specifiers || []).filter(
43-
specifier => specifier.type === 'ImportSpecifier',
44-
);
39+
const otherSpecifier = (path.value.specifiers || []).filter(
40+
specifier => specifier.type === 'ImportSpecifier',
41+
);
4542

46-
if (defaultSpecifier.length > 0) {
47-
return;
48-
}
43+
if (defaultSpecifier.length > 0) {
44+
return;
45+
}
4946

50-
const ds = otherSpecifier.find(s =>
51-
[innerElementName, existingAlias].includes(s.local?.name || null),
52-
);
53-
const ni = otherSpecifier.filter(
54-
s => ![innerElementName, existingAlias].includes(s.local?.name || null),
55-
);
56-
const declaration = j.importDeclaration(
57-
[j.importDefaultSpecifier(ds && ds.local), ...ni],
58-
j.literal(pkg),
59-
);
47+
const ds = otherSpecifier.find(s =>
48+
[innerElementName, existingAlias].includes(s.local?.name || null),
49+
);
50+
const ni = otherSpecifier.filter(
51+
s =>
52+
![innerElementName, existingAlias].includes(s.local?.name || null),
53+
);
54+
const declaration = j.importDeclaration(
55+
[j.importDefaultSpecifier(ds && ds.local), ...ni],
56+
j.literal(pkg),
57+
);
6058

61-
j(path).replaceWith(declaration);
62-
});
63-
};
59+
j(path).replaceWith(declaration);
60+
});
61+
};
6462

6563
const elevateStatelessToDefault = elevateComponentToDefault(
6664
'@atlaskit/breadcrumbs',

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

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,35 @@ import {
55
getImportSpecifierName,
66
} from '@codeshift/utils';
77

8-
const createRemoveFuncFor = (
9-
importSource: string,
10-
importName: string,
11-
prop: string,
12-
predicate: (j: core.JSCodeshift, element: ASTPath<any>) => boolean = () =>
13-
true,
14-
comment?: string,
15-
) => (j: core.JSCodeshift, source: Collection<Node>) => {
16-
const specifier = getImportSpecifierName(j, source, importName, importSource);
8+
const createRemoveFuncFor =
9+
(
10+
importSource: string,
11+
importName: string,
12+
prop: string,
13+
predicate: (j: core.JSCodeshift, element: ASTPath<any>) => boolean = () =>
14+
true,
15+
comment?: string,
16+
) =>
17+
(j: core.JSCodeshift, source: Collection<Node>) => {
18+
const specifier = getImportSpecifierName(
19+
j,
20+
source,
21+
importName,
22+
importSource,
23+
);
1724

18-
if (!specifier) return;
25+
if (!specifier) return;
1926

20-
source.findJSXElements(specifier).forEach(element => {
21-
if (predicate(j, element) && comment) {
22-
insertCommentToStartOfFile(j, source, comment);
23-
} else {
24-
getJSXAttributes(j, element, prop).forEach(attribute => {
25-
j(attribute).remove();
26-
});
27-
}
28-
});
29-
};
27+
source.findJSXElements(specifier).forEach(element => {
28+
if (predicate(j, element) && comment) {
29+
insertCommentToStartOfFile(j, source, comment);
30+
} else {
31+
getJSXAttributes(j, element, prop).forEach(attribute => {
32+
j(attribute).remove();
33+
});
34+
}
35+
});
36+
};
3037

3138
const removeHasSeparator = createRemoveFuncFor(
3239
'@atlaskit/breadcrumbs',

community/@atlaskit__breadcrumbs/11.0.0/motions/rename-breadcrumbs.ts

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -33,40 +33,46 @@ function getSafeImportName(
3333
return doesIdentifierExist(j, base, desiredName) ? fallbackName : desiredName;
3434
}
3535

36-
const createRenameJSXFunc = (
37-
component: string,
38-
from: string,
39-
to: string,
40-
fallback: string | undefined = undefined,
41-
) => (j: core.JSCodeshift, source: any) => {
42-
const defaultSpecifier = getDefaultImportSpecifierName(j, source, component);
36+
const createRenameJSXFunc =
37+
(
38+
component: string,
39+
from: string,
40+
to: string,
41+
fallback: string | undefined = undefined,
42+
) =>
43+
(j: core.JSCodeshift, source: any) => {
44+
const defaultSpecifier = getDefaultImportSpecifierName(
45+
j,
46+
source,
47+
component,
48+
);
4349

44-
const toName = fallback
45-
? getSafeImportName(j, source, defaultSpecifier!, to, fallback)
46-
: to;
50+
const toName = fallback
51+
? getSafeImportName(j, source, defaultSpecifier!, to, fallback)
52+
: to;
4753

48-
source
49-
.find(j.ImportDeclaration)
50-
.filter(
51-
(path: ASTPath<ImportDeclaration>) =>
52-
path.node.source.value === component,
53-
)
54-
.find(j.ImportDefaultSpecifier)
55-
.find(j.Identifier)
56-
.filter((p: ASTPath<Identifier>) => (p.value && p.value.name) === from)
57-
.forEach((path: ASTPath<ImportDeclaration>) => {
58-
j(path).replaceWith(j.importDefaultSpecifier(j.identifier(toName)));
59-
});
60-
61-
source.find(j.JSXElement).forEach((path: ASTPath<any>) => {
62-
return !!j(path.node)
63-
.find(j.JSXIdentifier)
64-
.filter(identifier => identifier.value.name === from)
65-
.forEach(element => {
66-
j(element).replaceWith(j.jsxIdentifier(toName));
54+
source
55+
.find(j.ImportDeclaration)
56+
.filter(
57+
(path: ASTPath<ImportDeclaration>) =>
58+
path.node.source.value === component,
59+
)
60+
.find(j.ImportDefaultSpecifier)
61+
.find(j.Identifier)
62+
.filter((p: ASTPath<Identifier>) => (p.value && p.value.name) === from)
63+
.forEach((path: ASTPath<ImportDeclaration>) => {
64+
j(path).replaceWith(j.importDefaultSpecifier(j.identifier(toName)));
6765
});
68-
});
69-
};
66+
67+
source.find(j.JSXElement).forEach((path: ASTPath<any>) => {
68+
return !!j(path.node)
69+
.find(j.JSXIdentifier)
70+
.filter(identifier => identifier.value.name === from)
71+
.forEach(element => {
72+
j(element).replaceWith(j.jsxIdentifier(toName));
73+
});
74+
});
75+
};
7076

7177
const renameBreadcrumbs = createRenameJSXFunc(
7278
'@atlaskit/breadcrumbs',

community/@atlaskit__button/15.1.1/__tests__/transform.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,7 @@ describe('@atlaskit/button@15.1.1 transform', () => {
176176

177177
check({
178178
transformer,
179-
it:
180-
'should add a warning when both the testId and data-testid props are being used',
179+
it: 'should add a warning when both the testId and data-testid props are being used',
181180
original: `
182181
import StandardButton from '@atlaskit/button';
183182

community/@atlaskit__button/15.1.1/transform.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ function getJSXAttributes(
3636
.filter(identifer => {
3737
j(identifer).closest(j.JSXOpeningElement);
3838
// Checking we are on the same level as the jsx element
39-
const closest = j(identifer)
40-
.closest(j.JSXOpeningElement)
41-
.nodes()[0];
39+
const closest = j(identifer).closest(j.JSXOpeningElement).nodes()[0];
4240

4341
if (!closest) {
4442
return false;

0 commit comments

Comments
 (0)