Skip to content

Commit

Permalink
feat(cli): add codemod to remove exit animations
Browse files Browse the repository at this point in the history
feature/codemods
  • Loading branch information
connor-baer committed Jun 1, 2020
1 parent 8bf5947 commit ba03c6c
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ module.exports = require('@sumup/foundry/eslint')(
rules: {
'import/no-unresolved': 'off',
'notice/notice': 'off',
'@typescript-eslint/no-unused-vars': 'off'
'@typescript-eslint/no-unused-vars': 'off',
'prettier/prettier': 'off'
}
},
{
Expand Down
23 changes: 23 additions & 0 deletions src/cli/migrate/__testfixtures__/exit-animations.input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import styled from '@emotion/styled';
import { LoadingButton } from '@sumup/circuit-ui';

const BaseLoadingButton = () => (
<LoadingButton
exitAnimation={LoadingButton.ERROR}
onAnimationComplete={console.log}
exitAnimationDuration={300}
/>
);

const RedLoadingButton = styled(LoadingButton)`
color: red;
`;

const StyledLoadingButton = () => (
<RedLoadingButton
exitAnimation={LoadingButton.ERROR}
onAnimationComplete={console.log}
exitAnimationDuration={300}
/>
);
15 changes: 15 additions & 0 deletions src/cli/migrate/__testfixtures__/exit-animations.output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import styled from '@emotion/styled';
import { LoadingButton } from '@sumup/circuit-ui';

const BaseLoadingButton = () => (
<LoadingButton />
);

const RedLoadingButton = styled(LoadingButton)`
color: red;
`;

const StyledLoadingButton = () => (
<RedLoadingButton />
);
1 change: 1 addition & 0 deletions src/cli/migrate/__tests__/transforms.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ defineTest(__dirname, 'list-variant-enum');
defineTest(__dirname, 'onchange-prop');
defineTest(__dirname, 'as-prop');
defineTest(__dirname, 'selector-props');
defineTest(__dirname, 'exit-animations');
49 changes: 49 additions & 0 deletions src/cli/migrate/exit-animations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Copyright 2020, SumUp Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { Transform } from 'jscodeshift';

import { findLocalNames } from './utils';

const transform: Transform = (file, api) => {
const j = api.jscodeshift;
const root = j(file.source);

const components = findLocalNames(j, root, 'LoadingButton');

if (!components) {
return;
}

components.forEach(component => {
['exitAnimation', 'exitAnimationDuration', 'onAnimationComplete'].forEach(
prop => {
root
.findJSXElements(component)
.find(j.JSXAttribute, {
name: {
type: 'JSXIdentifier',
name: prop
}
})
.remove();
}
);
});

return root.toSource();
};

export default transform;

0 comments on commit ba03c6c

Please sign in to comment.