Overview:
I have written a few mathematica packages, always using the method of writing my code in a mathematica notebook and letting mathematica autogenerate the .m package file. Currently I do not have the mathematica notebook frontend available (I am using Wolfram Engine only) and I want to use and edit those .m packages I generated a while ago. Unfortunately the .m files generated by mathematica are a huge mess because all tabs for formatting seem to have been removed when autogenerating the package from the mathematica notebook. So whilst the notebook looked fine for me the mathematica package is close to "unreadable".
Here is an example:
Screenshot from the code in the mathematica notebook:

Same code in the autogenerated package:
getMeanColorsHelper[image_?ImageQ,n_?IntegerQ,method_:"KMeans",distanceFunction_:EuclideanDistance]:= Module[{colorCluster ,i,meanColors,order,rules,nChannels,imageGray,meanColorsGray},
meanColors = Table[0,{i,n}];
nChannels = ImageChannels[image];
If[nChannels>1,meanColorsGray = Table[0,{i,n}]];
If[nChannels>1,imageGray = ColorConvert[image,"Grayscale"]];
colorCluster = ClusteringComponents[image,n,Method->method,DistanceFunction->distanceFunction,RandomSeeding->RandomInteger[{1,10000}]];
For[i=1,i<=n,i++,
meanColors[[i]] = Flatten[Pick[ImageData[image],colorCluster,i],1]//Mean;
If[nChannels>1,meanColorsGray[[i]]=Flatten[Pick[ImageData[imageGray],colorCluster,i],1]//Mean];
];
order = If[nChannels>1,Ordering[meanColorsGray],Ordering[meanColors]];
rules = MapIndexed[#1->First@#2&,order];
meanColors = meanColors[[#]]&/@order;
If[nChannels==1,meanColors=List[#]&/@meanColors;];
Return[meanColors];
];
So I have two questions:
1) Does anybody know about a way to automatically format my .m package files to make them readable without manually inserting all the tabs again? (maybe some code linter, ...)
(note: I do not want to format the mathematica notebook file but the .m file, which can be read by a standard text editor)
2) Is there a way to make mathematica autogenerate packages with proper indentation, so I could avoid these problems in the future (should I have access to the mathematica frontend again)?
