Skip to content

Instantly share code, notes, and snippets.

@eethann
Created December 15, 2011 16:41
Show Gist options
  • Save eethann/1481785 to your computer and use it in GitHub Desktop.
Save eethann/1481785 to your computer and use it in GitHub Desktop.
Simple sed script to resolve common Drupal.org coding standards violations.
#!/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