Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple sed script to resolve common coding standards violations.
#!/usr/bin/env sed -f
# whitespace at end of lines
# 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
# inline comments must start with capital
# inline comments must end with punctuation
# 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
# 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