Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Terminal command to help you find preprocessor code smells in Objective-C code
find . \( \( -name "*.[chm]" -o -name "*.mm" \) -o -name "*.cpp" \) -print0 | xargs -0 egrep -n '^\w*\#' | egrep -v '(import|pragma|else|endif|HC_SHORTHAND|MOCKITO_SHORTHAND)'
Owner

jonreid commented Oct 5, 2011

This command examines source files from the current directory down, showing preprocessor use that you should double-check.

See "9 Code Smells of Preprocessor Use" http://qualitycoding.org/preprocessor/

donarb commented Feb 2, 2013

You might want to exclude 'include' statements in your script as well. Legacy C code will trigger false positives otherwise.

EDIT: Oh duh, just read the first point about preprocessor smells, but legacy code gets a pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment