OCLint指令集文档
[toc]
跳转位置
oclint指令集
基本使用:oclint [options] <source0> [... <sourceN>]
oclint [oclint options] <source0> [... <sourceN>] -- [compiler options]
想要改变oclint 的行为,options参数 需要 在文件资源前面添加,比如 导出报告:-html -o report.html
想要改变 编译行为,需要在 -- 后面添加参数.
以我的项目为例:
kIsysroot="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.4.sdk"
kFilePath="LXCategory/AppDelegate.m"
# 编译文件
clang -x objective-c -arch armv7 -std=gnu99 -fobjc-arc -O0 -isysroot $kIsysroot -g -I./Pods/Headers -c $kFilePath
# 分析文件
oclint -report-type=html -o=report.html $kFilePath -- -x objective-c -arch armv7 -std=gnu99 -fobjc-arc -O0 -isysroot $kIsysroot -g -I ./Pods/Headers -c
参数说明:
参数 | 使用说明 | 备注 |
---|---|---|
-R= |
添加指定的规则加载路径 | 默认是项目根目录 |
-fatal-assembler-warnings | 将警告视为错误 | |
-help | ||
-max-priority-1= |
第一优先级错误最大个数 | |
-max-priority-2= |
||
-max-priority-3= |
||
-o= |
报告文件导出路径 | |
-p= |
build路径 | |
-rc= |
覆盖默认的行为规则 | |
-stats | 启用程序的统计输出 | |
-text | 纯文本报告类型输出 | |
-html | HTML格式类型报告输出 | |
-version | oclint版本信息 | |
-p |
用于读取编译命令数据库 | |
待分析的资源文件 |
规则加载选项
- -R
:通过-R参数可以修改规则加载路径。可以从多个路径中加载多个规则。默认从 $(/path/to/bin/oclint)/../lib/oclint/rules
加载规则。 - -rc
= : 某些规则具有确定是否发出违规行为的阈值。这些阈值可以通过带有 -rc key=value
的兼职对进行更改。
编译选项
例如你平时编译一个文件:
clang -x objective-c -arch armv7 -std=gnu99 -fobjc-arc -O0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.4.sdk -g -I./Pods/Headers -c RPActivityIndicatorManager.m
当你分析这个代码时的OCLint命令将是:
oclint [oclint options] RPActivityIndicatorManager.m -- -x objective-c -arch armv7 -std=gnu99 -fobjc-arc -O0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.4.sdk -g -I./Pods/Headers -c
- -p : 重定向build路径。这个路径内需要包含名为compile_commands.json的文件。如果未指定构建路径,则将尝试通过第一个输入文件的所有父路径搜索compile_commands.json。
检查分析选项
导出报告相关参数
-
-o
: 指定导出文件的路径和文件名 -
-text : 导出纯文本报告
-
-html : 导出HTML 格式报告
-report-type=html -o=./oclint_report.html
退出状态选项
-max-priority-1 <threshold>
一级违例最大数量-max-priority-2 <threshold>
二级违例最大数量-max-priority-3 <threshold>
三级违例最大数量
OCLint返回以下四个退出代码之一:
-
- SUCCESS
-
- RULE_NOT_FOUND
-
- ERROR_WHILE_PROCESSING
-
- VIOLATIONS_EXCEED_THRESHOLD
oclint-json-compilation-database 指令集
# 使用方法
oclint-json-compilation-database [<filter0> ... <filterN>] -- [oclint options]
# 使用实例
oclint-json-compilation-database -e LXCategory/Third -i LXCategory/test -- \
-report-type html -o ./AppOutput/oclint-out/oclint_report.html \
-max-priority-1=100000 \
-max-priority-2=100000 -max-priority-3=100000 \
-disable-rule=InvertedLogic \
-disable-rule=CollapsibleIfStatements \
-disable-rule=UnusedMethodParameter \
-disable-rule=LongVariableName \
-disable-rule=ShortVariableName \
-disable-rule=UselessParentheses \
-disable-rule=IvarAssignmentOutsideAccessorsOrInit \
- -i INCLUDES, -include INCLUDES, –include INCLUDES Extract files matching pattern from compile_commands.json or prior matching result
- -e EXCLUDES, -exclude EXCLUDES, –exclude EXCLUDES Remove files matching pattern from compile_commands.json or prior matching result
- -v show invocation command with arguments
oclint-xcodebuild 指令集
该指令集已经不维护 使用xcpretty代替