Use OCLint and Sonar for iOS code analysis and quality management, oclintios
OCLint is a powerful static code analysis tool that can be used to improve code quality and find potential bugs, mainly for Static Analysis of c, c ++ and Objective-c.
Sonar is an open platform for code quality management. With the plug-in mechanism, Sonar can integrate different test tools, code analysis tools, and continuous integration tools.
Install SonarQube
SonarQube Chinese
Chinese INS
Https://github.com/SonarQubeCommunity/sonar-l10n-zh
Put the downloaded file in the following directory:
1 |
/Usr/local/Cellar/sonarqube/6.5/libexec/extensions/plugins |
Install Mysql
Create a sonar Database
Configure sonar to connect to mysql
123456 |
Sonar. jdbc. url = jdbc: mysql: // localhost: 3306/sonar? UseUnicode = true & characterEncoding = utf8 & rewriteBatchedStatements = true & useConfigs = maxPerformance & useSSL = falsesonar. jdbc. username = rootsonar. jdbc. password = rootsonar. sorceEncoding = UTF-8sonar.login = adminsonar. password = admin |
Install xcpretty
Install OCLint
12 |
Brew tap oclint/formulabrew install oclint |
Install sonar-plugin
1 |
Brew install sonar-Example |
Install sonar-objective-c-plugin
Backelite-sonar-objective-c-plugin-0.6.2.jar
Put the downloaded file in the following directory:
1 |
/Usr/local/Cellar/sonarqube/6.5/libexec/extensions/plugins |
Restart sonar
Now the Sonar environment has been basically configured. Open http: // 127.0.0.1: 9000
Project Configuration
Setrun-sonar.shAndsonar-project.propertiesPut the template in the root directory and modify it..propertiesFile content, and then executerun-sonar.shYou can. File address https://github.com/LeoXu92/SonarShell-iOS
Final Effect
(Ps. The technical debt accumulation is quite large, so it's time to change it .)
The system prompts "The rule 'xxx' does not exist" when executing sonar-example"
In the new oclint version, some rules are added. You need to update the rule list on the sonar server.
Download https://github.com/leoxu92/sonar-objective-ccode.
Then, in the path sonar-objective-c-develop/sonar-objective-c-plugin/src/main/resources/org/sonar/plugins/oclintprofile-oclint.xmlAndrules.txtThese two files. Add the corresponding rule.
Then executebuild-and-deploy.shCompile a new jar package.
If SonarQube cannot be started
Deletesonarqube/6.7.1/libexec/tempRestart the folder.