Normalise and enforce script formatting/indentation
thc202 opened this issue · 3 comments
thc202 commented
Per title, might be asking too much given the number of languages...
sourabhdeshmukh commented
@thc202 could you please give more details regarding which scripts needs formating.
kingthorin commented
I started to look at this based on spotless. I figured first I should look at implementing it for JavaScript. Using the eclipse web tool platform formatter fails (it does run but bombs with syntax errors).
Stack & Console output
$ ./gradlew spotlessApply
> Task :spotlessJs FAILED
Skipping 'C:\Users\thorin\Desktop\zap-ws\community-scripts\active\Cross Site WebSocket Hijacking.js' because it does not converge. Run `spotlessDiagnose` to understand why
Skipping 'C:\Users\thorin\Desktop\zap-ws\community-scripts\active\JWT None Exploit.js' because it does not converge. Run `spotlessDiagnose` to understand why
Skipping 'C:\Users\thorin\Desktop\zap-ws\community-scripts\active\User defined attacks.js' because it does not converge. Run `spotlessDiagnose` to understand why
Step 'eclipse wtp formatters - JS' found problem in 'extender\HTTP Message Logger.js':
Invalid JavaScript syntax for formatting.
java.lang.IllegalArgumentException: Invalid JavaScript syntax for formatting.
at com.diffplug.spotless.extra.eclipse.wtp.EclipseJsFormatterStepImpl.format(EclipseJsFormatterStepImpl.java:96)
at jdk.internal.reflect.GeneratedMethodAccessor21.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep.lambda$applyWithoutFile$1(EclipseWtpFormatterStep.java:64)
at com.diffplug.spotless.FormatterFunc.apply(FormatterFunc.java:32)
at com.diffplug.spotless.FormatterStepImpl$Standard.format(FormatterStepImpl.java:78)
at com.diffplug.spotless.FormatterStep$Strict.format(FormatterStep.java:76)
at com.diffplug.spotless.Formatter.compute(Formatter.java:230)
...
So then I thought to just use some of the default methods for formatting: trimTrailingWhitespace()
, indentWithSpaces()
, endWithNewline()
. However, the indent method doesn't replace existing indentation 😢 It will changes tabs to spaces, but it doesn't replace existing space indentation.