Skip to content

Instantly share code, notes, and snippets.

Last active Nov 26, 2020
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)'
Copy link

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"

Copy link

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