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
importtype{API,FileInfo,Options}from'jscodeshift';import{getPrintOptions}from'../getPrintOptions';functiontransform(file: FileInfo,api: API,options: Options){constj=api.jscodeshift;// alias the jscodeshift APIconstroot=j(file.source);// parse JS code into an ASTconstprintOptions=getPrintOptions(options);letlinesToRemove=[];root.find(j.ObjectExpression).forEach((path)=>{// Find properties in the objectconstproperties=path.node.properties;// // Sort properties by their starting line numberconstsortedProperties=properties.sort((a,b)=>a.loc.start.line-b.loc.start.line);// Remove any blank lines between propertiesfor(leti=0;i<sortedProperties.length-1;i++){constendLine=sortedProperties[i].loc.end.line;constnextStartLine=sortedProperties[i+1].loc.start.line;// Remove empty lines between propertiesif(nextStartLine-endLine>=1){for(letline=endLine+1;line<nextStartLine;line++){linesToRemove=[
...linesToRemove,line,];console.log({
line,});}}}returnpath.node;});// linesToRemove.sort((a, b) => b - a).map((line) => {// root.find(j.Literal).at(line).remove();// root.find(j.Identifier).at(line).remove();// root.find(j.Literal, { loc: { start: { line } } }).remove();// });returnroot.toSource(printOptions);}module.exports=transform;module.exports.parser='tsx';
The text was updated successfully, but these errors were encountered:
I believe that anything involving spacing is going to be taking place at the recast layer as opposed to the jscodeshift layer, so it's kind of out of our hands.
You'd probably get the most mileage out of creating lint/prettier rules for your codebase and running the transformed code through that, which is what I understand what Meta does when they use jscodeshift.
I want to transform this
into this
this is my first approach
The text was updated successfully, but these errors were encountered: