Skip to content

Instantly share code, notes, and snippets.

@jonreid

jonreid/gist:1258076

Last active Nov 26, 2020
Embed
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)'
@jonreid

This comment has been minimized.

Copy link
Owner Author

@jonreid 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" https://qualitycoding.org/xcode-preprocessor-macros/

@donarb

This comment has been minimized.

Copy link

@donarb 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