Skip to content

Commit d6aa68c

Browse files
committed
Finish Static Analysis
1 parent 0030ef5 commit d6aa68c

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

issue-5/iOS项目的持续集成与管理.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,40 @@ Gcovr输出的代码覆盖率报告也会被插件[Cobertura Jenkins plugin](htt
130130

131131
现在我们不仅可以看到测试是否通过,还可以看到代码的测试覆盖范围。
132132

133+
#Static Analysis
134+
One of the most powerful set of tools to keep code quality high is static analysis. These tools will scan your code and generate a report of where your code breaks one of the code style rules. Some examples of these rules are:
135+
136+
* Unused variables or parameters
137+
* Long variable names, method names or lines
138+
* Overriding a method and not calling super on a method that requires it
139+
* Overly long or complex methods
140+
* And so on…
141+
142+
We use OCLint which is a static analysis tool which works with C, C++ and Objective-C. OCLint provides great integration with XCTool using a special json-compilation-database reporter. We first need to add a second reporter to our XCTool command and then pass that report to OCLint to perform the static analysis.
143+
144+
```
145+
$ xctool -workspace Project.xcworkspace -scheme Project -reporter junit:junit-report.xml -reporter json-compilation-database:compile_commands.json test
146+
$ oclint-json-compilation-database -e Pods -report-type pmd -o oclint-pmd.xml
147+
148+
```
149+
150+
The report generated is in the PMD format and can then be published in Jenkins by the PMD Plugin. With this plugin you can also set limits to how many of each priority of warning (low, medium and high) there can be before the tests fail. We initially set these limits low so we are alerted as soon as we introduce code that could be improved.
151+
152+
#静态分析
153+
在工具集中,其中一个强大并能够保持高质量的代码的工具就是静态分析工具。这些工具会扫描你的代码,然后生成一个报告,这个报告会告诉你破坏代码风格规则的代码位置。举几个规则的例子:
154+
155+
* 未使用的变量或参数
156+
* 长变量名,方法名或代码行
157+
* 覆盖一个方法,但没有在这个方法调用*super*
158+
* 方法太长或方法过于复杂
159+
* 还更多的规格...
160+
161+
我们使用[OCLint](http://oclint.org/)静态分析工具,这个工具能够支持C,C++和Objective-C语言。OCLint通过结合XCTool使用来生成**json-compilation-database** reporter
162+
,从而提供[great integration](http://docs.oclint.org/en/dev/guide/xctool.html)特性。我们首先添加另一个reporter到我们的XCTool命令行,然后将那个report传递到OCLint来执行静态分析。
163+
164+
```
165+
$ xctool -workspace Project.xcworkspace -scheme Project -reporter junit:junit-report.xml -reporter json-compilation-database:compile_commands.json test
166+
$ oclint-json-compilation-database -e Pods -report-type pmd -o oclint-pmd.xml
167+
168+
```
169+
这个report以[PMD](http://pmd.sourceforge.net/)的方式来生成,然后使用[PMD Plugin](https://wiki.jenkins-ci.org/display/JENKINS/PMD+Plugin)被发布到Jenkins。有了这些插件之后,你也可以在测试失败之前,设置每个警告的优先级(底,中,高)中一些限制。最初,我们设置这些限制为低,那么只要我们引入代码,就会被提醒,从而提高代码质量。

0 commit comments

Comments
 (0)