IBLinter

August 25, 2019 ยท View on GitHub

Build Status Swift 5.0

A linter tool to normalize .xib and .storyboard files. Inspired by realm/SwiftLint

Installation

Using Homebrew

$ brew install IBDecodable/homebrew-tap/iblinter

Using CocoaPods

pod 'IBLinter'

This will download the IBLinter binaries and dependencies in Pods/ during your next pod install execution and will allow you to invoke it via ${PODS_ROOT}/IBLinter/bin/iblinter in your Script Build Phases.

Compiling from source

You can build from source by cloning this repository and running

$ make install

iblinter will be installed in /usr/local/bin.

Usage

You can see all description by iblinter help

$ iblinter help
Available commands:

   help      Display general or command-specific help
   lint      Print lint warnings and errors (default command)
   version   Display the current version of iblinter

Xcode

Add a Run Script Phase to integrate IBLinter with Xcode

if which iblinter >/dev/null; then
  iblinter lint
else
  echo "warning: IBLinter not installed, download from https://github.com/IBDecodable/IBLinter"
fi

Alternatively, if you've installed IBLinter via CocoaPods the script should look like this:

"${PODS_ROOT}/IBLinter/bin/iblinter"

Requirements

IBLinter requires Swift5.0 runtime. Please satisfy at least one of following requirements.

Rules

All rules are documented in Rules.md

Pull requests are encouraged.

Configuration

You can configure IBLinter by adding a .iblinter.yml file from project root directory.

keydescription
enabled_rulesEnabled rules id.
disabled_rulesDisabled rules id.
excludedPath to ignore for lint.
includedPath to include for lint.
custom_module_ruleCustom module rule configs.
use_base_class_ruleUse base class rule configs.
view_as_device_ruleView as device rule configs.

CustomModuleConfig

You can configure custom_module rule by CustomModuleConfig list.

keydescription
moduleModule name.
includedPath to *.swift classes of the module for custom_module lint.
excludedPath to ignore for *.swift classes of the module for custom_module lint.

UseBaseClassConfig

You can configure use_base_class rule by UseBaseClassConfig list.

keydescription
element_classElement class name.
base_classesBase classes of the element class.

Note: UseBaseClassRule does not work for classes that inherit base class. You need to add all classes to base_classes to check.

ViewAsDeviceConfig

You can configure view_as_device rule by ViewAsDeviceConfig. If there are no config, device_id is set as retina4_7.

keydescription
device_idDevice id for device.

appx. Table of mapping device name to device_id (on Xcode 10.2)

device namedevice id
iPhone 4sretina3_5
iPhone SEretina4_0
iPhone 8retina4_7
iPhone 8 Plusretina5_5
iPhone XSretina5_9
iPhone XRretina6_1
iPhone XS Maxretina6_5
enabled_rules:
  - relative_to_margin
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