Swi$Lint
@ikesyo
関西モバイルアプリ研究会 #10, 2016-01-27 Wed
#関モバ
@ikesyo
ikesyo_nnid
いけしょー/池田翔
京都でフリーランスのiOSエンジニア
(時々Android)しています
フリュー㈱のモバイル開発の
チームにジョイン中。
✨ Contribu*ons ✨
• Himotoki
• Carthage
• Reac0veCocoa
• APIKit
• Result
• AMScrollingNavbar
try! Swi)2016.3.2∼2016.3.4
東京・渋谷
閑話休題
3人チーム
@yashigani
@niwatako
@ikesyo <- New❗
コードレビュー
• スタイルの指摘に時間取られたくないよね
• 自動化
• 余計なことに頭を使わない
• ユーザーに価値を届けることに集中するために
Swi$Lint
Swi$Lint
• h#ps://github.com/realm/Swi7Lint
• $ brew install swiftlint
• Swi7用のlintツール
• Swi7製
• SourceKi#en
• Swi7XPC sourcekitd.h (from apple/swi7)
• Commandant
• Result
• SWXMLHash
• YamlSwi7
History
• 2015-05-18: 0.1.0
• 2015-10-01: 0.2.0 ... Swi. 2.0, .swiftlint.yml, Custom reporters
• 2015-11-04: 0.3.0
• 2015-11-18: 0.4.0
• 2015-12-13: 0.5.0 ... autocorrect
• 2016-01-15: 0.6.0 ... Various auto-correc?on, Opt-in rules, Dic?onary format config
• 2016-01-25: 0.7.0 ... More configurable rules, CyclomaticComplexityRule
• 2016-01-27: 0.7.1 ... Custom Rules through regular expression (#416)
.swi%lint.yml
disabled_rules: # rule identifiers to exclude from running
- colon
- comma
- control_statement
enabled_rules: # some rules are only opt-in
- empty_count
- missing_docs
# Find all the available rules by running:
# swiftlint rules
included: # paths to include during linting. `--path` is ignored if present.
- Source
excluded: # paths to ignore during linting. Takes precedence over `included`.
- Carthage
- Pods
- Source/ExcludedFolder
- Source/ExcludedFile.swift
.swi%lint.yml
# configurable rules can be customized from this configuration file
# binary rules can set their severity level
force_cast: warning # implicitly
force_try:
severity: warning # explicitly
# rules that have both warning and error levels, can set just the warning level
# implicitly
line_length: 110
# they can set both implicitly with an array
type_body_length:
- 300 # warning
- 400 # error
# or they can set both explicitly
file_length:
warning: 500
error: 1200
.swi%lint.yml
# naming rules can set warnings/errors for min_length and max_length
# additionally they can set excluded names
type_name:
min_length: 4 # only warning
max_length: # warning and error
warning: 40
error: 50
excluded: iPhone # excluded via string
variable_name:
min_length: # only min_length
error: 4 # only error
excluded: # excluded via string array
- id
- URL
- GlobalAPIKey
reporter: "csv" # reporter type (xcode, json, csv, checkstyle)
Nested Configura/ons
• use_nested_configs: true
• ルート階層の設定と、特定のディレクトリ以下で設定を変えた
い場合
Disable a rule in code
例外を弾いてルール全体を無効化しないようにする。
// swiftlint:disable colon
let noWarning :String = "" // ここは警告されない
// swiftlint:enable colon
let hasWarning :String = "" // ここは警告される
// swiftlint:disable:next force_cast <- 次の行だけ無効
let noWarning = NSNumber() as! Int
let hasWarning = NSNumber() as! Int
let noWarning2 = NSNumber() as! Int // swiftlint:disable:this force_cast <- この行だけ無効
let noWarning3 = NSNumber() as! Int
// swiftlint:disable:previous force_cast <- 前の行だけ無効
Auto-correct
• swiftlint autocorrect
• 一部のルールでは自動修正が可能 (0.7.0時点で以下の10個)
• closing_brace, colon, comma
• legacy_constant, legacy_constructor, opening_brace
• statement_posi;on, trailing_newline
• trailing_semicolon, trailing_whitespace
• disabled_rules にあるものは修正もされない。
• 差分を少なくしながら導入できる !
To contribute
• Improve lin-ng performance (let's follow @norio-nomura! !)
• Implement new rules
• Fix bugs
• ...
! Happy Swi) lin,ng!! !
Thank you❗"

SwiftLint