Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Perl-based Java codebase aesthetics format scrubber.
#!/usr/bin/env bash
set -o errexit
set -o pipefail
set -o nounset
for f in $(find . -name '*.java'); do
perl \
-0 \
-i \
-pe 's/((\) \{|try \{|class .* \{)\n|\n\n)\n+/\1/g;' \
-pe 's/(import +[^;]*;)\n\n+(import [^;]*;\n)\n*/\1\n\2/g;' \
-pe 's/(import +static [^;]*;)\n(import ([^s]|s[^t]|st[^a]|sta[^t]|stat[^i]|stati[^c]|static[^ ])[^;]*;)/\1\n\n\2/g;' \
-pe 's/(import ([^s]|s[^t]|st[^a]|sta[^t]|stat[^i]|stati[^c]|static[^ ])[^;]*;)\n(import +static [^;]*;)/\1\n\n\3/g;' \
"${f}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.