Created
May 5, 2021 21:16
-
-
Save elderbas/fab8e8123228faa113f66ba889e22891 to your computer and use it in GitHub Desktop.
codemod script to add import statement of `useEffectOnce`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default (fileInfo, api) => { | |
const j = api.jscodeshift; | |
const root = j(fileInfo.source); | |
const importLine = `import useEffectOnce from 'utils/useEffectOnce';`; | |
const imports = root.find(j.ImportDeclaration); | |
const n = imports.length; | |
j(imports.at(n - 1).get()).insertAfter(importLine); // after the imports | |
return root.toSource(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment