- 进入~/Documents/oclint/目录,执行:
oclint-scripts/scaffoldRule BlockUseStrongSelfRule -t ASTVisitor
其中“BlockUseStrongSelfRule”是定义的检查规则名称;“ASTVisitor”是你继承的规则种类。
这里可以继承如下规则:SourceCodeReader、ASTVisitor、ASTMatcher。
- 执行完上述命令后,分别在以下路径生成对应的文件:
~/Documents/oclint/oclint-rules/rules/custom
~/Documents/oclint/oclint-rules/test/custom
- 为了方便开发,可以生成xcodeproj文件,回到oclint目录,执行以下命令:
cd ~/Documents/oclint
mkdir oclint-xcoderules
cd oclint-xcoderules
touch create-xcode-rules.sh
chmod 777 create-xcode-rules.sh
打开create-xcode-rules.sh并添加以下内容
#! /bin/sh -e
cmake -G Xcode \
-D CMAKE_CXX_COMPILER=../build/llvm-install/bin/clang++ \
-D CMAKE_C_COMPILER=../build/llvm-install/bin/clang \
-D OCLINT_BUILD_DIR=../build/oclint-core \
-D OCLINT_SOURCE_DIR=../oclint-core \
-D OCLINT_METRICS_SOURCE_DIR=../oclint-metrics \
-D OCLINT_METRICS_BUILD_DIR=../build/oclint-metrics \
-D LLVM_ROOT=../build/llvm-install/ ../oclint-rules
-
执行:./create-xcode-rules.sh
在oclint-xcoderules目录下会生成以下文件:
-
打开OCLINT_RULES.xcodeproj,会发现Sources目录下面有很多文件夹,自定义的Rule一般都是在最下面:
-
我们修改并build自定义的Rule后,会生成对应的:libBlockUseStrongSelfRule.dylib,要立即使用新生成的Rule,就要把新生成的dylib文件复制到:~/Documents/oclint/oclint-release/lib/oclint/rules
复制的操作可以添加脚本简化:
cp ~/Documents/oclint/oclint-xcoderules/rules.dl/Debug/libCustomObjectiveCRule.dylib \
~/Documents/oclint/build/oclint-release/lib/oclint/rules/libCustomObjectiveCRule.dylib

