💻
ExistOrLive' Gitbook
  • README
  • ReadMe
  • 开发语言学习
    • Python
      • 0.概述
      • 1.基本数据类型
      • 2.变量
      • 3.函数
      • 4.运算符
      • 5.字符串
      • 6.列表
      • 7.元组
      • 8.集合
      • 9.字典
      • 10.流程控制
      • 12.函数
      • 13.模块
      • 14.输入输出格式化
      • 15.面向对象
    • Swift
      • 1.基础部分
        • 常量和变量以及基本类型_1
        • 常量和变量以及基本类型_2
      • 2.基本运算符
        • 基本运算符
      • 3.字符串和字符
        • 字符串
        • 字符串操作
      • 4.集合类型
        • 概述
        • Array
        • Set
        • Dictionary
      • 6.函数
        • 函数
        • 函数返回值
        • 函数类型
      • 7.闭包
        • 闭包
        • 闭包表达式
        • 尾随闭包
        • 捕获变量或常量
        • 闭包是引用类型
        • 逃逸闭包
        • 自动闭包
      • 8.枚举
        • 枚举
        • 枚举与switch语句
      • 9.类和结构体
        • 类和结构体
        • 属性
          • 属性
          • 属性观察器
          • 属性包装器
          • 全局变量和局部变量
          • 类属性
        • 方法
    • Shell
      • Shell变量和基本类型
      • Shell函数
      • Shell基本运算符
      • Shell脚本的参数
      • Shell流程控制
      • Shell输入输出
      • Shell文件包含
  • iOS
    • UI
      • UIKit
        • UIView
          • UIView
          • drawRect
        • UITableView
          • UITableView
          • UITableView的加载过程
  • 学习开发工具
    • 静态分析
      • OCLint
      • infer
      • SwiftLint
    • iOS构建工具
      • fastlane
        • fastlane
        • fastlane的安装
        • fastlane一键打包
        • fastlane证书管理
    • Cocoapods
      • 安装pod库-podfile
      • 创建pod库-podspec
  • 开源库
    • Tool
      • Swiftlint源码学习
      • 利用Swiftlint自定义规则实现自动化code review
由 GitBook 提供支持
在本页
  • OCLint 安装
  • OCLint 使用
  • 问题
  • 参考文档

这有帮助吗?

在GitHub上编辑
  1. 学习开发工具
  2. 静态分析

OCLint

在ios开发过程中,我们使用Clang这个前端编译工具,将OC代码输出为抽象语法树,然后编译成LLVM的bitcode,最后再编译成machine code。OCLint就是基于Clang实现的通过检查C,C++和Objective-C代码来提高代码质量、降低错误率的静态代码分析工具,代码通过OCLint检测后,可以发现一些潜在的问题。OCLint检测依赖源代码的抽象语法树来保证精准度和效率,尽可能减少误报,同时动态加载规则到系统中进行检测

OCLint 安装

brew install oclint

OCLint 使用

  • 首先使用 xcodebuild analyze 分析代码,在用xcpretty将分析报告解析为 compile_commands.json

xcodebuild analyze -workspace ZLGitHubClient.xcworkspace -scheme ZLGitHubClient | tee  $analyzeDirPath"/analyze.log" | xcpretty --report json-compilation-database -o $analyzeDirPath'/compile_commands.json'
  • 使用oclint-json-compilation-database 将 compile_commands.json 转化为可视化的报告

oclint-json-compilation-database  -p $analyzeDirPath -- -report-type pmd -o $analyzeDirPath'/report.html'

问题

  • oclint: error: Not enough positional command line arguments specified!

解决办法 :

在podfile中添加

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

在pod工程中将COMPILER_INDEX_STORE_ENABLE改为NO

  • oclint: Not enough positional command line arguments specified!

解决办法:https://github.com/oclint/oclint/issues/478

参考文档

上一页静态分析下一页infer

最后更新于3年前

这有帮助吗?

OCLint的基础使用
OCLint官方文档