IBLinter
用于规范 .xib 和 .storyboard 文件的代码检查工具。受到 realm/SwiftLint 的启发
安装
使用 Homebrew
$ brew install IBDecodable/homebrew-tap/iblinter使用 CocoaPods
pod 'IBLinter'这将使您在下次执行 pod install 时,在 Pods/ 目录下下载 IBLinter 的二进制文件和相关依赖,并允许您在 Script Build Phases 中通过 ${PODS_ROOT}/IBLinter/bin/iblinter 调用它。
从源代码编译
通过克隆此仓库并运行以下命令可以从源代码构建
$ make install
iblinter 将被安装到 /usr/local/bin。
用法
您可以通过运行iblinter help来查看所有描述。
lint命令用于打印代码检查的警告和信息(默认命令)。--path参数默认为当前目录。
Xcode
将一个Run Script Phase添加到Xcode,以集成IBLinter。
if which iblinter >/dev/null; then
iblinter lint
else
echo "warning: IBLinter not installed, download from https://github.com/IBDecodable/IBLinter"
fi如果您通过CocoaPods安装了IBLinter,脚本应该如下:
"${PODS_ROOT}/IBLinter/bin/iblinter"规则
| 规则ID | 描述 |
|---|---|
自定义类名 |
Storyboard中ViewController的自定义类名应与文件名相同。 |
相对于边距 |
禁止使用相对于边距选项。 |
位置错误 |
当视图位置错误时显示错误。 |
启用自动布局 |
强制使用useAutolayout选项 |
重复约束 |
当视图有重复约束时显示警告。 |
StoryboardViewController ID |
检查Storyboard ID是否与ViewController类名相同。 |
图像资源 |
检查图像资源是否有效。 |
鼓励提交拉取请求。
配置
您可以通过在项目根目录中添加一个.iblinter.yml文件来配置IBLinter。
| 键 | 描述 |
|---|---|
启用规则 |
启用规则的ID。 |
禁用规则 |
禁用规则的ID。 |
排除 |
忽略代码检查的路径。 |
enabled_rules:
- relative_to_margin
disabled_rules:
- custom_class_name
excluded:
- Carthage