下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
【移动应用开发技术】怎么通过静态分析提高iOS代码质量
SwiftLint安装$
brew
install
swiftlintpod
'SwiftLint',
:configurations
=>
['Debug']集成进Xcodeif
which
swiftlint
>/dev/null;
then
swiftlint
else
echo
"warning:
SwiftLint
not
installed,
download
from
/realm/SwiftLint"
fi"${PODS_ROOT}/SwiftLint/swiftlint"运行SwiftLint定制disabled_rules:
#
rule
identifiers
to
exclude
from
running
-
colon
-
trailing_whitespace
-
vertical_whitespace
-
function_body_length
opt_in_rules:
#
some
rules
are
only
opt-in
-
empty_count
#
Find
all
the
available
rules
by
running:
#
swiftlint
rules
included:
#
paths
to
include
during
linting.
`--path`
is
ignored
if
present.
-
Source
excluded:
#
paths
to
ignore
during
linting.
Takes
precedence
over
`included`.
-
Carthage
-
Pods
-
Source/ExcludedFolder
-
Source/ExcludedFile.swift
-
Source/*/ExcludedFile.swift
#
Exclude
files
with
a
wildcard
analyzer_rules:
#
Rules
run
by
`swiftlint
analyze`
(experimental)
-
explicit_self
#
configurable
rules
can
be
customized
from
this
configuration
file
#
binary
rules
can
set
their
severity
level
force_cast:
warning
#
implicitly
force_try:
severity:
warning
#
explicitly
#
rules
that
have
both
warning
and
error
levels,
can
set
just
the
warning
level
#
implicitly
line_length:
110
#
they
can
set
both
implicitly
with
an
array
type_body_length:
-
300
#
warning
-
400
#
error
#
or
they
can
set
both
explicitly
file_length:
warning:
500
error:
1200
#
naming
rules
can
set
warnings/errors
for
min_length
and
max_length
#
additionally
they
can
set
excluded
names
type_name:
min_length:
4
#
only
warning
max_length:
#
warning
and
error
warning:
40
error:
50
excluded:
iPhone
#
excluded
via
string
allowed_symbols:
["_"]
#
these
are
allowed
in
type
names
identifier_name:
min_length:
#
only
min_length
error:
4
#
only
error
excluded:
#
excluded
via
string
array
-
id
-
URL
-
GlobalAPIKey
reporter:
"xcode"
#
reporter
type
(xcode,
json,
csv,
checkstyle,
junit,
html,
emoji,
sonarqube,
markdown)!
Function
Body
Length
Violation:
Function
body
should
span
40
lines
or
less
excluding
comments
and
whitespace:
currently
spans
43
lines
(function_body_length)生成报告#
reporter
type
(xcode,
json,
csv,
checkstyle,
junit,
html,
emoji,
sonarqube,
markdown)
$
swiftlint
lint
--reporter
html
>
swiftlint.htmlxcodebuild#
不带pod的项目,target名为TargetName,在Debug下,指定模拟器sdk环境进行编译
xcodebuild
-target
TargetName
-configuration
Debug
-sdk
iphonesimulator
#
带pod的项目,workspace名为TargetName.xcworkspace,在Release下,scheme为TargetName,指定真机环境进行编译。不指定模拟器环境会验证证书
xcodebuild
-workspace
WorkspaceName.xcworkspace
-scheme
SchemeName
Release
#
清楚项目的编译产物
xcodebuild
-workspace
WorkspaceName.xcworkspace
-scheme
SchemeName
Release
clean之后对xcodebuild命令的使用都需要将这些参数替换为自己项目的参数。Infer安装及使用$
brew
install
infer$
cd
projectDir
#
跳过对Pods的分析
$
infer
run
--skip-analysis-in-path
Pods
--
xcodebuild
-workspace
"Project.xcworkspace"
-scheme
"Scheme"
-configuration
Debug
-sdk
iphonesimulator$
infer
explore
--html$
xcodebuild
-workspace
"Project.xcworkspace"
-scheme
"Scheme"
-configuration
Debug
-sdk
iphonesimulator
clean$
infer
run
--skip-analysis-in-path
Pods
--
xcodebuild
-workspace
"Project.xcworkspace"
-scheme
"Scheme"
-configuration
Debug
-sdk
iphonesimulatorInfer的大致原理1、捕获阶段2、分析阶段OCLint$
brew
tap
oclint/formulae
$
brew
install
oclint$
oclint
--version
LLVM
(/):
LLVM
version
5.0.0svn-r313528
Optimized
build.
Default
target:
x86_64-apple-darwin19.0.0
Host
CPU:
skylake
OCLint
(/):
OCLint
version
0.13.
Built
Sep
18
2017
(08:58:40).1
error
generated
1
error
generated
...
oclint:
error:
cannot
open
report
output
file
/onlintReport.html编译OCLint$
brew
install
cmake
ninja$
git
clone
/oclint/oclint$
./make设置oclint工具的环境变量OCLint_PATH=/Users/zhangferry/oclint/build/oclint-release
export
PATH=$OCLint_PATH/bin:$PATH$
oclint
--version
OCLint
(/):
OCLint
version
0.15.
Built
May
19
2020
(11:48:49).安装xcpretty$
gem
install
xcprettyOCLint的使用post_install
do
|installer|
installer.pods_project.targets.each
do
|target|
target.build_configurations.each
do
|config|
config.build_settings['COMPILER_INDEX_STORE_ENABLE']
=
"NO"
end
end
end$
xcodebuild
-workspace
ProjectName.xcworkspace
-scheme
ProjectScheme
-configuration
Debug
-sdk
iphonesimulator
|
xcpretty
-r
json-compilation-database
-o
compile_commands.json$
oclint-json-compilation-database
-e
Pods
--
-report-type
html
-o
oclintReport.html
-rc
LONG_LINE=9999
-max-priority-1=9999
-max-priority-2=9999
-max-priority-3=9999封装脚本#!/bin/bash
#
mark
sure
you
had
install
the
oclint
and
xcpretty
#
You
need
to
replace
these
values
with
your
own
project
configuration
workspace_name="WorkSpaceName.xcworkspace"
scheme_name="SchemeName"
#
remove
history
rm
compile_commands.json
rm
oclint_result.xml
#
clean
project
#
-sdk
iphonesimulator
means
run
simulator
xcodebuild
-workspace
$workspace_name
-scheme
$scheme_name
-configuration
Debug
-sdk
iphonesimulator
clean
||
(echo
"command
failed";
exit
1);
#
export
compile_commands.json
xcodebuild
-workspace
$workspace_name
-scheme
$scheme_name
-configuration
Debug
-sdk
iphonesimulator
\
|
xcpretty
-r
json-compilation-database
-o
compile_commands.json
\
||
(echo
"command
failed";
exit
1);
#
export
report
html
#
you
can
run
`oclint
-help`
to
see
all
USAGE
oclint-json-compilation-database
-e
Pods
--
-report-type
html
-o
oclintReport.html
\
-disable-rule
ShortVariableName
\
-rc
LONG_LINE=1000
\
||
(echo
"command
failed";
exit
1
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 5G无线网络技术建设难点及应对策略
- 4G远程控制装置在野外地震台站中的应用
- 3种乳酸菌鉴定、筛选、富硒比较研究
- 300MW级燃煤发电工程采用双管式套筒烟囱的探讨
- 2020年高考“选考内容”专题解题分析
- 2017年10月固原一次大到暴雪型寒潮天气过程分析
- 16~#洞进场路桥涵施工技术探讨
- 10种常见绿化树种重金属积累特性的研究
- 1000MW机组抽真空系统配置优化探索
- 儿童高血压-防治知识手册
- 《如何写导游词》课件
- 安全脚手架和梯子使用规范
- 小学课题泥塑研究报告范文
- 2023初中学业水平考试美术复习试题含答案
- 《3D打印技术》课程标准2
- 探索直线平行的条件1
- 一站式商业步行街项目规划设计方案
- 儿童消费金融行业分析
- 2024年泰康保险集团招聘笔试参考题库含答案解析
- 医德医风培训课件
- 眼科专科质量监测指标汇总
评论
0/150
提交评论