一个用于规范化 .xib
和 .storyboard
文件的 linter 工具。灵感来自 realm/SwiftLint。
$ brew install iblinter
$ mint install IBDecodable/IBLinter
pod 'IBLinter'
这将在您下次执行 pod install
时下载 IBLinter 二进制文件和依赖项到 Pods/
目录中,并允许您通过脚本构建阶段中的 ${PODS_ROOT}/IBLinter/bin/iblinter
调用它。
您可以通过克隆此仓库并运行以下命令从源码构建:
$ make install
iblinter
将被安装在 /usr/local/bin
中。
您可以使用 iblinter --help
查看所有描述。
$ iblinter --help
USAGE: iblinter <subcommand>
OPTIONS:
--version Show the version.
-h, --help Show help information.
SUBCOMMANDS:
lint (default) Print lint warnings and errors
See 'iblinter help <subcommand>' for detailed help.
添加一个 Run Script Phase
来将 IBLinter 集成到 Xcode 中。
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"
IBLinter 需要 Swift5.0 运行时。请满足以下至少一个要求。
Swift 5 Runtime Support for Command Line Tools
。所有规则都记录在 Rules.md 中。
欢迎提交 Pull requests。
您可以通过在项目根目录中添加 .iblinter.yml
文件来配置 IBLinter。
key | 描述 |
---|---|
enabled_rules |
已启用的规则 ID。 |
disabled_rules |
已禁用的规则 ID。 |
excluded |
要忽略进行 lint 的路径。 |
included |
要包含进行 lint 的路径。 |
custom_module_rule |
自定义模块规则配置。 |
use_base_class_rule |
使用基类规则配置。 |
view_as_device_rule |
以设备视图规则配置。 |
您可以通过 CustomModuleConfig
列表配置 custom_module
规则。
key | 描述 |
---|---|
module |
模块名称。 |
included |
用于 custom_module lint 的模块 *.swift 类的路径。 |
excluded |
用于 custom_module lint 的模块 *.swift 类的忽略路径。 |
您可以通过 UseBaseClassConfig
列表配置 use_base_class
规则。
key | 描述 |
---|---|
element_class |
元素类名。 |
base_classes |
元素类的基类。 |
注意:UseBaseClassRule 不适用于继承基类的类。 您需要将所有类添加到 base_classes
进行检查。
您可以通过 ViewAsDeviceConfig
配置 view_as_device
规则。 如果没有配置,则 device_id
设置为 retina4_7
。
key | 描述 |
---|---|
device_id |
设备的设备 ID。 |
近似值。 设备名称到 device_id
的映射表(在 Xcode 10.2
上)
设备名称 | 设备 ID |
---|---|
iPhone 4s |
retina3_5 |
iPhone SE |
retina4_0 |
iPhone 8 |
retina4_7 |
iPhone 8 Plus |
retina5_5 |
iPhone XS |
retina5_9 |
iPhone XR |
retina6_1 |
iPhone XS Max |
retina6_5 |
您可以通过 UseTraitCollectionsConfig
配置 use_trait_collections
规则。 如果没有配置,则 use_trait_collections 设置为 true。
key | 描述 |
---|---|
enabled | true |
您可以通过 HidesBottomBarConfig
列表配置 hides_bottom_bar
规则。
key | 描述 |
---|---|
excluded_view_controllers |
要忽略 hides_bottom_bar 规则的控制器的类名。 |
enabled_rules:
- relative_to_margin
- use_trait_collections
- hides_bottom_bar
- has_single_view_controller
- has_initial_view_controller
disabled_rules:
- custom_class_name
excluded:
- Carthage
- App
included:
- App/Views
custom_module_rule:
- module: UIComponents
included:
- UIComponents/Classes
excluded:
- UIComponents/Classes/Config/Generated
use_base_class_rule:
- element_class: UILabel
base_classes:
- PrimaryLabel
- SecondaryLabel
view_as_device_rule:
device_id: retina4_0
use_trait_collections_rule:
enabled: false
hides_bottom_bar_rule:
excluded_view_controllers:
- FirstViewController
- SecondViewController