I Am Writing a python script to sort of clean code in files.. Mainly Javascript files so what i've done so far is remove line breaks and end the line after each semi colon, But what i would like to do is check whether a string is in between parentheses or not if its not then i want to end the line after a semi colon if it is i want to leave it alone and keep going.. im guessing i need to use read lines? Heres an output example of what im talking about
for(var c=clus.length-1;
0<=c;
c--){var e=clus[c];
As you can see it ends the line after each semi colon , but i dont want that to happen between parentheses.. Any help on this? Here is my code..
import re, getpass, time
curUser=str(getpass.getuser()) # Get Current User;
dateOfUse=str(time.strftime('%x')) # Get Current Date;
FileToRead=open(r'C:/Users/' + curUser + '/Desktop/script.js', 'r') # File to open;
FileToWrite=open(r'C:/Users/' + curUser + '/Desktop/generated2.js', 'w') # File to Write / Will replace file if exists;
data=str(FileToRead.read()) # Read our file;
data=data.replace('\n', '').replace('\r', '') # Remove all Line Breaks to bring code together;
data=re.sub(r'(;)', r';\n\n', data) # End line after every Semi-colon;
FileToWrite.write('/* Cleaned ' + dateOfUse + ' */\n\n' + data) # Write data to our new file;