Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalise and enforce script formatting/indentation #170

Open
thc202 opened this issue Oct 24, 2019 · 3 comments
Open

Normalise and enforce script formatting/indentation #170

thc202 opened this issue Oct 24, 2019 · 3 comments

Comments

@thc202
Copy link
Member

thc202 commented Oct 24, 2019

Per title, might be asking too much given the number of languages...

@sourabhdeshmukh
Copy link

@thc202 could you please give more details regarding which scripts needs formating.

@thc202
Copy link
Member Author

thc202 commented Feb 24, 2020

The ones under the script type directories (e.g. active).

@zaproxy zaproxy deleted a comment from An-spectator Jul 17, 2020
@kingthorin
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants