Skip to content

Instantly share code, notes, and snippets.

@chales
Forked from eethann/drupalcs_fix.sed
Last active December 17, 2015 23:40
Show Gist options
  • Save chales/69f3e74bd264ecd67973 to your computer and use it in GitHub Desktop.
Save chales/69f3e74bd264ecd67973 to your computer and use it in GitHub Desktop.
#!/usr/bin/env sed -f
# whitespace at end of lines
s/\s\+$//
# fix comma followed by non-space character
# don't be picky, this is correct even for text!
/function/!s/\(,\)\(\S\)/\1 \2/g
# fix comments may not appear after statements
/http/!s/^\(\s*\)\(\S.*\)\(\/\/.*\)$/\1\3\n\1\2/
# inline comments must start with capital
s/\(\/\/\s*\)\([[:lower:]]\)/\1\u\2/
# inline comments must end with punctuation
s/\(\/\/.*[^[:punct:]]$\)/\1./
# no whitespace before comment text
s/\(\/\/\)\(\S\)/\1 \2/
# operator statement must be preceded by a space
s/\(\S\)\([!=]*={1,2}\)/\1 \2/
# operator statement must be followed by a space
# note that we need to take care to avoid =>
s/\([!=]*=\{1,2\}\)\([^[:space:]>=&]\)/\1 \2/
# TODO: cast followed by single space
# TODO: else on new line
# param comments on next line
s/\( \* \)\(@param \S\+ \S\+\) \(.\+\)$/\1\2\n\1 \3/
# return comments on next line
s/\( \* \)\(@return \S\+\) \(.\+\)$/\1\2\n\1 \3/
# whitespace at end of lines
s/\s\+$//
# Implementation comment spec
s/Implementation of hook_\(.*\)[.()[:space:]]*$/Implements hook_\1()./
# Concat operator
s/\(\S\)\./\1 ./g
s/\.\(\S\)/. \1/g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment