Last active
November 29, 2021 12:19
-
-
Save CTimmerman/fd8a42cc6548cb92c0ce923c3293e1a0 to your computer and use it in GitHub Desktop.
Simple code cleaner. Use Git to check the non-whitespace edits such as <>.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# entire file, CLI code, inplace | |
perl -0777pe " | |
# whitespace | |
s/ /\t/g; # Tabs indent at a uniform and viewer-custom size. | |
s/\t +/\t\t/g; # Do not mix tabs and spaces. | |
s/ / /g; | |
s/\r\n/\n/g; # Nor line endings. | |
s/(catch|for|foreach|function|if|switch|while)\s+\(/\1\(/g; # Compact flow. | |
s/\}\s+el(if|se)/\}el\1/g; | |
s/\s+\{/\{/g; # Useless when indenting. | |
s/([,;])([^ \n'\"])/\1 \2/g; # Read and wrap better. | |
s/{(\d+), (\d+)}/{\1,\2}/g; # Fix regex ranges. | |
s/\s*([!<=>.+-]+=>*)\s*/ \1 /g; # Read and wrap != etc. | |
s/\s*([!<=>.+-]=+>*)([^\\ \t\n'\"=>&])\s*/ \1 \2/g; | |
s/\s*([^= -])(<|>)\\\$\s*/ \1\2 \\\$/g; | |
#s/ (class|href|language|style|type) = / \1=/g; # Should be in templates. | |
s/[\t ]+\n/\n/g; # No trailing whitespace. | |
s/\n\n\n+/\n\n/g; # One empty line is enough. Use functions or comments to separate more. | |
# standards | |
s/\s*<>\s*/ != /g; # Not using BASIC anymore. | |
" -i $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
GitHub failed to find "perl" in this gist, so maybe this comment helps.