假设我想在我的代码中检测一些我无法通过测试检查的东西。
例如。:
- 检查我的整个代码库以检测我在括号和大括号之间有一个空格(使用正则表达式)。
- 浏览我的整个代码库并检测风格异味。
等等...
如果其中一项检查失败,我想显示我自己定义的自定义警告。
XCode 中有这样的东西吗?
谢谢。
最佳答案
我为 Xcode 编写了一个 run script,它完全符合您的要求。它通过正则表达式搜索预定义的“代码味道”或“风格味道”,并在编译时向您发出警告
阅读博客文章,但最终脚本在这里
#test if git exists.
command -v git > /dev/null 2>$1 || {exit 0}
#separate code smells with | i.e. (code_smell_1|code_smell_2)
KEYWORDS="(didDeselectRowAtIndexPath)"
git diff --name-only HEAD | grep "\.m" | xargs egrep -s --with-filename --line-number --only-matching "$KEYWORDS.*[^\/]*$" | perl -p -e "s/($KEYWORDS)/ warning: Are you sure you want to use \$1?\nTo remove this warning, append a comment at the end of this line \$1/"
此特定脚本在代码中搜索
didDeselectRowAtIndexPath
的出现,但您可以将其更改为任何字符串关于ios - 在 XCode 中构建项目时,有没有办法显示自定义警告?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23358846/