You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(I originally suggested this codemod here: skovhus/jest-codemods#53)
I do not have time to write a PR but you might want to add something like this:
/** * A quick code mod to move from using a sinon global to using sinon 2.x with an import statement. */// findImports, hasRequireOrImport stolen from// https://github.com/skovhus/jest-codemods/blob/master/src/utils/imports.jsfunctionfindImports(j,ast,pkg){returnast.find(j.ImportDeclaration,{source: {value: pkg}})}/** * Detects CommonJS and import statements for the given package. * @return true if import were found, else false */functionhasRequireOrImport(j,ast,pkg){// const requires = findRequires(j, ast, pkg).size()constimports=findImports(j,ast,pkg).size()returnimports>0}functionhasIdentifier(j,ast,name){returnast.find(j.Identifier,{
name
}).size()>0}module.exports=function(fileInfo,api){constj=api.jscodeshiftconstast=j(fileInfo.source)if(!hasRequireOrImport(j,ast,'sinon')&&hasIdentifier(j,ast,'sinon')){letimp=ast.find(j.ImportDeclaration,{})// console.log(imp)letnode=imp.at(imp.size()-1)const{statement}=j.template// const newNode = j.importDeclaration('sinon', 'sinon');node.insertAfter(statement`import sinon from 'sinon'`)returnnode.toSource()}}
The text was updated successfully, but these errors were encountered:
(I originally suggested this codemod here: skovhus/jest-codemods#53)
I do not have time to write a PR but you might want to add something like this:
The text was updated successfully, but these errors were encountered: