注意: 目前使用者可能遇到一些问题,比如 “dyld: Library not loaded: @rpath/lib_InternalSwiftSyntaxParser.dylib” 或者无法显示warning. 这是SwiftSyntax 问题, SwiftSyntax with Swift 5.1, 请查看.
reporter: "xcode"
disabled_rules:
- skip_public
included: # paths to include during detecting. `--path` is ignored if present.
- ./
excluded: # paths to ignore during detecting. Takes precedence over `included`.
- Carthage
- Pods
excludedGroupName: # names of group to ignore during detecting.
- SwiftPeckerTestUITests
blacklist_files: # files to ignore during detecting, only need to add file name, the file extension default is swift.
- HomeViewController
blacklist_symbols: # symbols to ignore during detecting, contains class, struct, enum, etc.
- AppDelegate
- viewDidLoad
blacklist_superclass: # all the class inherit from class specified in the list will ignore
- UITableViewCell
# If output_file is not specified, the defaults to be pecker.result.json in your project
output_file: pecker.result.jsonthe path can be both relative and absolute.
Pecker
pecker
是一个自动检测无用代码的工具,它基于 IndexStoreDB 和 SwiftSyntax。如果你有什么疑问可以随时联系我,我的推特 Roy,邮箱:
roy.cao1991@gmail.com
。为什么使它?
在我们的项目开发过程中,会写很多代码,随着时间推移,很多代码已经不再使用了,但是想发现他们并不容易。
pecker
能很自动的帮你定位到它们。功能
pecker
能检测以下几种无用的代码.安装
使用 Homebrew
使用 CocoaPods:
在下一次执行
pod install
时将会把 pecker 的二进制文件和依赖下载到Pods/
目录下并且将允许你通过 {PODS_ROOT}/Pecker/bin/pecker` 在 Script Build Phases 中调用 pecker。自从 Pecker 支持安装某个特定版本后,安装一个指定版本的 Pecker 是目前推荐的做法相比较于简单地选择最新版本安装的话。
使用 Mint:
手动
之后
pecker
就被安装到你的bin
目录下,现在你就可以使用它了。用法
Xcode
整合 Pecker 到 Xcode 体系中去从而可以使警告和错误显示到 IDE 上,只需要在 Xcode 中添加一个新的“Run Script Phase”并且包含如下代码即可:
或者,如果你已经通过 CocoaPods 安装了 Pecker,可以使用如下脚本:
终端
例子:
.pecker.yml
配置:终端输入
命令行
-v/--version
: 打印pecker
版本.--config
: 自定义yaml 配置文件路径.-i/--index-store-path
: 项目Index路径,如果没有指定,默认是~Library/Developer/Xcode/DerivedData/{your project}/Index/DataStore。在指定项目中执行
pecker
,将会遍历检测所有的swift文件。Rules
目前
pecker
仅有5个规则,他们是skip_public
、xctest
、attributes
、xml
和comment
,如果你不需要这些中的某些规则,可以把它添加到disabled_rules
中。你和可以在Source/PeckerKit/Rules
中查看他们的实现。skip_public
这个规则规定忽略public的class,struct,function等. 通常public的代码是开放给他人用的,很难判定这些代码是否是无用的。所以默认不检测public的代码。但有些时候,比如使用
submodule
的方式组织代码,那么你又想检测public的代码,你只需要把它添加到disabled_rules
中。xctest
XCTest 很特别,我们规定忽略继承自XCTest的类,以及以”test”开头但没有参数的方法。
attributes
如果一个声明的修饰符中包含
BlackListAttribute
中的case, 忽略这个检测。例如IBAction
,我们在持续收集这些修饰符,如果你发现新的cases,请告诉我们。xml
如果代码在xib或者storyboard中被用到,也表示被使用。。如果你不需要这个规则,可以把它添加到
disabled_rules
中。comment
可以通过在源代码中添加如下注释来忽略检测:
例如:
For example:
Other rules
一下这些规则是默认使用的,你不能配置它们。
override
跳过声明为override的方法,包含子类的override方法和protocol extension override方法。
extensions
extension也是引用,但是我们判定这不算做不被使用。
Configuration
这个是可选的,如果不配置将使用默认的。在
perker
项目中添加.pecker.yml
,以下参数可以配置:规则包含:
disabled_rules
: 从默认启用中禁用规则。报告方式包含:
pecker.result.json
的文件,你可以通过output_file
来自定义路径,这个路径可以为相对路劲和绝对路径,如果没有指定,默认为当前检测项目的文件下pecker.result.json
。贡献和支持
pecker
完全是一开放的方法开发。任何的贡献和pull requests都很受欢迎。如果你对开发
pecker
很感兴趣,提交你的想法和pull requests!协议
MIT License许可。