Skip to content

Instantly share code, notes, and snippets.

@jonreid
Last active November 26, 2020 11:09
Show Gist options
  • Save jonreid/1258076 to your computer and use it in GitHub Desktop.
Save jonreid/1258076 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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