Skip to content

Instantly share code, notes, and snippets.

@crespoxiao
Created January 31, 2018 08:38
Show Gist options
  • Save crespoxiao/e5ec18352d6f59dadf482620dbc53894 to your computer and use it in GitHub Desktop.
Save crespoxiao/e5ec18352d6f59dadf482620dbc53894 to your computer and use it in GitHub Desktop.
Showing TODO as warning in Xcode project
1. solution 1 --- add run script
TAGS="TODO:|FIXME:|XXX:"
echo "searching patch is ${SRCROOT}"
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/"
2. solution 2 --- by code
#define STRINGIFY(S) #S
#define DEFER_STRINGIFY(S) STRINGIFY(S)
#define PRAGMA_MESSAGE(MSG) _Pragma(STRINGIFY(message(MSG)))
#define FORMATTED_MESSAGE(MSG) "[TODO-" DEFER_STRINGIFY(__COUNTER__) "] " MSG " \n" \
DEFER_STRINGIFY(__FILE__) " line " DEFER_STRINGIFY(__LINE__)
#define KEYWORDIFY try {} @catch (...) {}
#define TODO(MSG) KEYWORDIFY PRAGMA_MESSAGE(FORMATTED_MESSAGE(MSG))
eg: @TODO("make a test by crespo")
@crespoxiao
Copy link
Author

TODO inside XXModules (ignore XXModules/Common/Pods)

TAGS="TODO:|FIXME:|XXX:"
SKIPDIRS="$(dirname $(pwd))/XXModules/Common/Pods"

find "$(dirname $(pwd))/XXModules/" -type f ( -name ".h" -or -name ".m" -or -name ".swift" ) -print0
| xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).
$"
| grep -v "$SKIPDIRS"
| perl -p -e "s/($TAGS)/ warning: $1/"

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