iOS集成OCLint实现代码自动检测

本文介绍了如何在Mac环境中配置Jenkins,并结合OCLint进行代码质量检测。首先通过Homebrew安装OCLint,然后安装xcpretty。在Xcode中,通过添加Run Script构建阶段来执行OCLint检测。接着,在终端中编写并执行shell脚本来运行oclint.sh,生成报告。最后,介绍了在Jenkins中安装PMD插件并添加构建脚本以集成OCLint。
摘要由CSDN通过智能技术生成

Mac 配置jenkins集成OCLint代码检测

一 .安装oclint

1.Homebrew安装OCLint

brew tap oclint/formulae
brew install oclint

输入oclint,验证

$ oclint
oclint: Not enough positional command line arguments specified!
Must specify at least 1 positional arguments: See: oclint -help

证明安装成功.

2、安装包安装
下载安装包source code(tar.gz) Git连接

二.安装xcpretty

sudo gem install -n /usr/local/bin  xcpretty

三.Xcode中代码检测

1.xcode 添加Run Script执行脚本

点击加号
在这里插入图片描述
创建一个新的Target,选择Aggregate
在这里插入图片描述添加Run Script
在这里插入图片描述

Xcode上Shell脚本,没有Pods的脚本编写代码:

source ~/.bash_profile
cd ${SRCROOT}
xcodebuild clean
xcodebuild build | tee xcodebuild.log | xcpretty -r json-compilation-database -o compile_commands.json
oclint-json-compilation-database -- -report-type Xcode

如果有cocoapods

source ~/.bash_profile
cd ${SRCROOT}
xcodebuild clean
xcodebuild  -workspace MISTSTrainer.xcworkspace -scheme MISTSTrainer | xcpretty -r json-compilation-database --output compile_commands.json
oclint-json-compilation-database -v \
-e Pods \

oclint_args -- -report-type xcode \
-disable-rule ObjCAssignIvarOutsideAccessors \
-disable-rule ShortVariableName \
-rc=MINIMUM_CASES_IN_SWITCH=3 \
-rc=CYCLOMATIC_COMPLEXITY=10 \
-rc=LONG_CLASS=700 \
-rc=LONG_LINE=200 \
-rc=NCSS_METHOD=40 \
-rc=NESTED_BLOCK_DEPTH=5 \
-rc=TOO_MANY_FIELDS=20 \
-rc=TOO_MANY_METHODS=30 \
-rc=TOO_MANY_PARAMETERS=6
exit

2.用shell脚本终端执行

进入工程文件夹下,在终端执行 vi oclint.sh

添加代码:

#!/bin/bash

# 指定编码
export LANG="zh_CN.UTF-8"
export LC_COLLATE="zh_CN.UTF-8"
export LC_CTYPE="zh_CN.UTF-8"
export LC_MESSAGES="zh_CN.UTF-8"
export LC_MONETARY="zh_CN.UTF-8"
export LC_NUMERIC="zh_CN.UTF-8"
export LC_TIME="zh_CN.UTF-8"


function checkDepend () {
   
command -v xcpretty >/dev/null 2>&1 || {
   
echo >&2 "I require xcpretty but it's not installed.  Install:gem install xcpretty";
exit
}
command -v oclint-json-compilation-database >/dev/null 2>&1 || {
   
echo >&2 "I require oclint-json-compilation-database but it's not installed.  Install:brew install oclint";
exit
}
}

function oclintForProject () {
   

# 检测依赖
checkDepend

projectName=$1
scheme=$2
reportType=$3

REPORT_PMD="pmd"
REPORT_XCODE="xcode"

mywork
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值