# Rules * [AnyObject Protocol](#anyobject-protocol) * [Array Init](#array-init) * [Attributes](#attributes) * [Block Based KVO](#block-based-kvo) * [Class Delegate Protocol](#class-delegate-protocol) * [Closing Brace Spacing](#closing-brace-spacing) * [Closure Body Length](#closure-body-length) * [Closure End Indentation](#closure-end-indentation) * [Closure Parameter Position](#closure-parameter-position) * [Closure Spacing](#closure-spacing) * [Colon](#colon) * [Comma Spacing](#comma-spacing) * [Compiler Protocol Init](#compiler-protocol-init) * [Conditional Returns on Newline](#conditional-returns-on-newline) * [Contains over first not nil](#contains-over-first-not-nil) * [Control Statement](#control-statement) * [Convenience Type](#convenience-type) * [Custom Rules](#custom-rules) * [Cyclomatic Complexity](#cyclomatic-complexity) * [Discarded Notification Center Observer](#discarded-notification-center-observer) * [Discouraged Direct Initialization](#discouraged-direct-initialization) * [Discouraged Object Literal](#discouraged-object-literal) * [Discouraged Optional Boolean](#discouraged-optional-boolean) * [Discouraged Optional Collection](#discouraged-optional-collection) * [Dynamic Inline](#dynamic-inline) * [Empty Count](#empty-count) * [Empty Enum Arguments](#empty-enum-arguments) * [Empty Parameters](#empty-parameters) * [Empty Parentheses with Trailing Closure](#empty-parentheses-with-trailing-closure) * [Empty String](#empty-string) * [Empty XCTest Method](#empty-xctest-method) * [Explicit ACL](#explicit-acl) * [Explicit Enum Raw Value](#explicit-enum-raw-value) * [Explicit Init](#explicit-init) * [Explicit Self](#explicit-self) * [Explicit Top Level ACL](#explicit-top-level-acl) * [Explicit Type Interface](#explicit-type-interface) * [Extension Access Modifier](#extension-access-modifier) * [Fallthrough](#fallthrough) * [Fatal Error Message](#fatal-error-message) * [File Header](#file-header) * [File Line Length](#file-line-length) * [File Name](#file-name) * [First Where](#first-where) * [For Where](#for-where) * [Force Cast](#force-cast) * [Force Try](#force-try) * [Force Unwrapping](#force-unwrapping) * [Function Body Length](#function-body-length) * [Function Default Parameter at End](#function-default-parameter-at-end) * [Function Parameter Count](#function-parameter-count) * [Generic Type Name](#generic-type-name) * [Identifier Name](#identifier-name) * [Implicit Getter](#implicit-getter) * [Implicit Return](#implicit-return) * [Implicitly Unwrapped Optional](#implicitly-unwrapped-optional) * [Inert Defer](#inert-defer) * [Is Disjoint](#is-disjoint) * [Joined Default Parameter](#joined-default-parameter) * [Large Tuple](#large-tuple) * [Leading Whitespace](#leading-whitespace) * [Legacy CGGeometry Functions](#legacy-cggeometry-functions) * [Legacy Constant](#legacy-constant) * [Legacy Constructor](#legacy-constructor) * [Legacy NSGeometry Functions](#legacy-nsgeometry-functions) * [Variable Declaration Whitespace](#variable-declaration-whitespace) * [Line Length](#line-length) * [Literal Expression End Indentation](#literal-expression-end-indentation) * [Lower ACL than parent](#lower-acl-than-parent) * [Mark](#mark) * [Missing Docs](#missing-docs) * [Modifier Order](#modifier-order) * [Multiline Arguments](#multiline-arguments) * [Multiline Function Chains](#multiline-function-chains) * [Multiline Parameters](#multiline-parameters) * [Multiple Closures with Trailing Closure](#multiple-closures-with-trailing-closure) * [Nesting](#nesting) * [Nimble Operator](#nimble-operator) * [No Extension Access Modifier](#no-extension-access-modifier) * [No Fallthrough Only](#no-fallthrough-only) * [No Grouping Extension](#no-grouping-extension) * [Notification Center Detachment](#notification-center-detachment) * [Number Separator](#number-separator) * [Object Literal](#object-literal) * [Opening Brace Spacing](#opening-brace-spacing) * [Operator Usage Whitespace](#operator-usage-whitespace) * [Operator Function Whitespace](#operator-function-whitespace) * [Overridden methods call super](#overridden-methods-call-super) * [Override in Extension](#override-in-extension) * [Pattern Matching Keywords](#pattern-matching-keywords) * [Prefixed Top-Level Constant](#prefixed-top-level-constant) * [Private Actions](#private-actions) * [Private Outlets](#private-outlets) * [Private over fileprivate](#private-over-fileprivate) * [Private Unit Test](#private-unit-test) * [Prohibited Interface Builder](#prohibited-interface-builder) * [Prohibited calls to super](#prohibited-calls-to-super) * [Protocol Property Accessors Order](#protocol-property-accessors-order) * [Quick Discouraged Call](#quick-discouraged-call) * [Quick Discouraged Focused Test](#quick-discouraged-focused-test) * [Quick Discouraged Pending Test](#quick-discouraged-pending-test) * [Redundant Discardable Let](#redundant-discardable-let) * [Redundant Nil Coalescing](#redundant-nil-coalescing) * [Redundant Optional Initialization](#redundant-optional-initialization) * [Redundant Set Access Control Rule](#redundant-set-access-control-rule) * [Redundant String Enum Value](#redundant-string-enum-value) * [Redundant Type Annotation](#redundant-type-annotation) * [Redundant Void Return](#redundant-void-return) * [Required Enum Case](#required-enum-case) * [Returning Whitespace](#returning-whitespace) * [Shorthand Operator](#shorthand-operator) * [Single Test Class](#single-test-class) * [Min or Max over Sorted First or Last](#min-or-max-over-sorted-first-or-last) * [Sorted Imports](#sorted-imports) * [Statement Position](#statement-position) * [Strict fileprivate](#strict-fileprivate) * [Superfluous Disable Command](#superfluous-disable-command) * [Switch and Case Statement Alignment](#switch-and-case-statement-alignment) * [Switch Case on Newline](#switch-case-on-newline) * [Syntactic Sugar](#syntactic-sugar) * [Todo](#todo) * [Toggle Bool](#toggle-bool) * [Trailing Closure](#trailing-closure) * [Trailing Comma](#trailing-comma) * [Trailing Newline](#trailing-newline) * [Trailing Semicolon](#trailing-semicolon) * [Trailing Whitespace](#trailing-whitespace) * [Type Body Length](#type-body-length) * [Type Name](#type-name) * [Unavailable Function](#unavailable-function) * [Unneeded Break in Switch](#unneeded-break-in-switch) * [Unneeded Parentheses in Closure Argument](#unneeded-parentheses-in-closure-argument) * [Untyped Error in Catch](#untyped-error-in-catch) * [Unused Closure Parameter](#unused-closure-parameter) * [Unused Enumerated](#unused-enumerated) * [Unused Import](#unused-import) * [Unused Optional Binding](#unused-optional-binding) * [Unused Private Declaration](#unused-private-declaration) * [Valid IBInspectable](#valid-ibinspectable) * [Vertical Parameter Alignment](#vertical-parameter-alignment) * [Vertical Parameter Alignment On Call](#vertical-parameter-alignment-on-call) * [Vertical Whitespace](#vertical-whitespace) * [Void Return](#void-return) * [Weak Delegate](#weak-delegate) * [XCTFail Message](#xctfail-message) * [Yoda condition rule](#yoda-condition-rule) -------- ## AnyObject Protocol Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `anyobject_protocol` | Disabled | Yes | lint | No | 4.1.0 Prefer using `AnyObject` over `class` for class-only protocols. ### Examples
Non Triggering Examples ```swift protocol SomeProtocol {} ``` ```swift protocol SomeClassOnlyProtocol: AnyObject {} ``` ```swift protocol SomeClassOnlyProtocol: AnyObject, SomeInheritedProtocol {} ``` ```swift @objc protocol SomeClassOnlyProtocol: AnyObject, SomeInheritedProtocol {} ```
Triggering Examples ```swift protocol SomeClassOnlyProtocol: ↓class {} ``` ```swift protocol SomeClassOnlyProtocol: ↓class, SomeInheritedProtocol {} ``` ```swift @objc protocol SomeClassOnlyProtocol: ↓class, SomeInheritedProtocol {} ```
## Array Init Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `array_init` | Disabled | No | lint | No | 3.0.0 Prefer using `Array(seq)` over `seq.map { $0 }` to convert a sequence into an Array. ### Examples
Non Triggering Examples ```swift Array(foo) ``` ```swift foo.map { $0.0 } ``` ```swift foo.map { $1 } ``` ```swift foo.map { $0() } ``` ```swift foo.map { ((), $0) } ``` ```swift foo.map { $0! } ``` ```swift foo.map { $0! /* force unwrap */ } ``` ```swift foo.something { RouteMapper.map($0) } ```
Triggering Examples ```swift ↓foo.map({ $0 }) ``` ```swift ↓foo.map { $0 } ``` ```swift ↓foo.map { return $0 } ``` ```swift ↓foo.map { elem in elem } ``` ```swift ↓foo.map { elem in return elem } ``` ```swift ↓foo.map { (elem: String) in elem } ``` ```swift ↓foo.map { elem -> String in elem } ``` ```swift ↓foo.map { $0 /* a comment */ } ```
## Attributes Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `attributes` | Disabled | No | style | No | 3.0.0 Attributes should be on their own lines in functions and types, but on the same line as variables and imports. ### Examples
Non Triggering Examples ```swift @objc var x: String ``` ```swift @objc private var x: String ``` ```swift @nonobjc var x: String ``` ```swift @IBOutlet private var label: UILabel ``` ```swift @IBOutlet @objc private var label: UILabel ``` ```swift @NSCopying var name: NSString ``` ```swift @NSManaged var name: String? ``` ```swift @IBInspectable var cornerRadius: CGFloat ``` ```swift @available(iOS 9.0, *) let stackView: UIStackView ``` ```swift @NSManaged func addSomeObject(book: SomeObject) ``` ```swift @IBAction func buttonPressed(button: UIButton) ``` ```swift @objc @IBAction func buttonPressed(button: UIButton) ``` ```swift @available(iOS 9.0, *) func animate(view: UIStackView) ``` ```swift @available(iOS 9.0, *, message="A message") func animate(view: UIStackView) ``` ```swift @nonobjc final class X ``` ```swift @available(iOS 9.0, *) class UIStackView ``` ```swift @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate ``` ```swift @UIApplicationMain class AppDelegate: NSObject, UIApplicationDelegate ``` ```swift @IBDesignable class MyCustomView: UIView ``` ```swift @testable import SourceKittenFramework ``` ```swift @objc(foo_x) var x: String ``` ```swift @available(iOS 9.0, *) @objc(abc_stackView) let stackView: UIStackView ``` ```swift @objc(abc_addSomeObject:) @NSManaged func addSomeObject(book: SomeObject) ``` ```swift @objc(ABCThing) @available(iOS 9.0, *) class Thing ``` ```swift class Foo: NSObject { override var description: String { return "" } } ``` ```swift class Foo: NSObject { override func setUp() {} } ``` ```swift @objc class ⽺ {} ``` ```swift extension Property { @available(*, unavailable, renamed: "isOptional") public var optional: Bool { fatalError() } } ``` ```swift @GKInspectable var maxSpeed: Float ``` ```swift @discardableResult func a() -> Int ``` ```swift @objc @discardableResult func a() -> Int ``` ```swift func increase(f: @autoclosure () -> Int) -> Int ``` ```swift func foo(completionHandler: @escaping () -> Void) ``` ```swift private struct DefaultError: Error {} ``` ```swift @testable import foo private let bar = 1 ``` ```swift import XCTest @testable import DeleteMe @available (iOS 11.0, *) class DeleteMeTests: XCTestCase { } ```
Triggering Examples ```swift @objc ↓var x: String ``` ```swift @objc ↓var x: String ``` ```swift @objc private ↓var x: String ``` ```swift @nonobjc ↓var x: String ``` ```swift @IBOutlet private ↓var label: UILabel ``` ```swift @IBOutlet private ↓var label: UILabel ``` ```swift @NSCopying ↓var name: NSString ``` ```swift @NSManaged ↓var name: String? ``` ```swift @IBInspectable ↓var cornerRadius: CGFloat ``` ```swift @available(iOS 9.0, *) ↓let stackView: UIStackView ``` ```swift @NSManaged ↓func addSomeObject(book: SomeObject) ``` ```swift @IBAction ↓func buttonPressed(button: UIButton) ``` ```swift @IBAction @objc ↓func buttonPressed(button: UIButton) ``` ```swift @available(iOS 9.0, *) ↓func animate(view: UIStackView) ``` ```swift @nonobjc final ↓class X ``` ```swift @available(iOS 9.0, *) ↓class UIStackView ``` ```swift @available(iOS 9.0, *) @objc ↓class UIStackView ``` ```swift @available(iOS 9.0, *) @objc ↓class UIStackView ``` ```swift @available(iOS 9.0, *) ↓class UIStackView ``` ```swift @UIApplicationMain ↓class AppDelegate: NSObject, UIApplicationDelegate ``` ```swift @IBDesignable ↓class MyCustomView: UIView ``` ```swift @testable ↓import SourceKittenFramework ``` ```swift @testable ↓import SourceKittenFramework ``` ```swift @objc(foo_x) ↓var x: String ``` ```swift @available(iOS 9.0, *) @objc(abc_stackView) ↓let stackView: UIStackView ``` ```swift @objc(abc_addSomeObject:) @NSManaged ↓func addSomeObject(book: SomeObject) ``` ```swift @objc(abc_addSomeObject:) @NSManaged ↓func addSomeObject(book: SomeObject) ``` ```swift @available(iOS 9.0, *) @objc(ABCThing) ↓class Thing ``` ```swift @GKInspectable ↓var maxSpeed: Float ``` ```swift @discardableResult ↓func a() -> Int ``` ```swift @objc @discardableResult ↓func a() -> Int ``` ```swift @objc @discardableResult ↓func a() -> Int ```
## Block Based KVO Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `block_based_kvo` | Enabled | No | idiomatic | No | 3.0.0 Prefer the new block based KVO API with keypaths when using Swift 3.2 or later. ### Examples
Non Triggering Examples ```swift let observer = foo.observe(\.value, options: [.new]) { (foo, change) in print(change.newValue) } ```
Triggering Examples ```swift class Foo: NSObject { override ↓func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {} } ``` ```swift class Foo: NSObject { override ↓func observeValue(forKeyPath keyPath: String?, of object: Any?, change: Dictionary?, context: UnsafeMutableRawPointer?) {} } ```
## Class Delegate Protocol Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `class_delegate_protocol` | Enabled | No | lint | No | 3.0.0 Delegate protocols should be class-only so they can be weakly referenced. ### Examples
Non Triggering Examples ```swift protocol FooDelegate: class {} ``` ```swift protocol FooDelegate: class, BarDelegate {} ``` ```swift protocol Foo {} ``` ```swift class FooDelegate {} ``` ```swift @objc protocol FooDelegate {} ``` ```swift @objc(MyFooDelegate) protocol FooDelegate {} ``` ```swift protocol FooDelegate: BarDelegate {} ``` ```swift protocol FooDelegate: AnyObject {} ``` ```swift protocol FooDelegate: NSObjectProtocol {} ```
Triggering Examples ```swift ↓protocol FooDelegate {} ``` ```swift ↓protocol FooDelegate: Bar {} ```
## Closing Brace Spacing Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `closing_brace` | Enabled | Yes | style | No | 3.0.0 Closing brace with closing parenthesis should not have any whitespaces in the middle. ### Examples
Non Triggering Examples ```swift [].map({ }) ``` ```swift [].map( { } ) ```
Triggering Examples ```swift [].map({ ↓} ) ``` ```swift [].map({ ↓} ) ```
## Closure Body Length Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `closure_body_length` | Disabled | No | metrics | No | 4.2.0 Closure bodies should not span too many lines. ### Examples
Non Triggering Examples ```swift foo.bar { $0 } ``` ```swift foo.bar { toto in } ``` ```swift foo.bar { toto in let a = 0 // toto // toto // toto // toto // toto // toto // toto // toto // toto // toto } ``` ```swift foo.bar { toto in let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 } ``` ```swift foo.bar { toto in let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 // toto // toto // toto // toto // toto // toto // toto // toto // toto // toto } ``` ```swift foo.bar({ toto in }) ``` ```swift foo.bar({ toto in let a = 0 }) ``` ```swift foo.bar({ toto in let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 }) ``` ```swift foo.bar(label: { toto in }) ``` ```swift foo.bar(label: { toto in let a = 0 }) ``` ```swift foo.bar(label: { toto in let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 }) ``` ```swift foo.bar(label: { toto in let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 }, anotherLabel: { toto in let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 }) ``` ```swift foo.bar(label: { toto in let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 }) { toto in let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 } ``` ```swift let foo: Bar = { toto in let bar = Bar() let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 return bar }() ```
Triggering Examples ```swift foo.bar ↓{ toto in let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 } ``` ```swift foo.bar ↓{ toto in let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 // toto // toto // toto // toto // toto // toto // toto // toto // toto // toto } ``` ```swift foo.bar(↓{ toto in let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 }) ``` ```swift foo.bar(label: ↓{ toto in let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 }) ``` ```swift foo.bar(label: ↓{ toto in let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 }, anotherLabel: ↓{ toto in let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 }) ``` ```swift foo.bar(label: ↓{ toto in let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 }) ↓{ toto in let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 } ``` ```swift let foo: Bar = ↓{ toto in let bar = Bar() let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 let a = 0 return bar }() ```
## Closure End Indentation Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `closure_end_indentation` | Disabled | Yes | style | No | 3.0.0 Closure end should have the same indentation as the line that started it. ### Examples
Non Triggering Examples ```swift SignalProducer(values: [1, 2, 3]) .startWithNext { number in print(number) } ``` ```swift [1, 2].map { $0 + 1 } ``` ```swift return match(pattern: pattern, with: [.comment]).flatMap { range in return Command(string: contents, range: range) }.flatMap { command in return command.expand() } ``` ```swift foo(foo: bar, options: baz) { _ in } ``` ```swift someReallyLongProperty.chainingWithAnotherProperty .foo { _ in } ``` ```swift foo(abc, 123) { _ in } ``` ```swift function( closure: { x in print(x) }, anotherClosure: { y in print(y) }) ``` ```swift function(parameter: param, closure: { x in print(x) }) ``` ```swift function(parameter: param, closure: { x in print(x) }, anotherClosure: { y in print(y) }) ```
Triggering Examples ```swift SignalProducer(values: [1, 2, 3]) .startWithNext { number in print(number) ↓} ``` ```swift return match(pattern: pattern, with: [.comment]).flatMap { range in return Command(string: contents, range: range) ↓}.flatMap { command in return command.expand() ↓} ``` ```swift function( closure: { x in print(x) ↓}, anotherClosure: { y in print(y) ↓}) ```
## Closure Parameter Position Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `closure_parameter_position` | Enabled | No | style | No | 3.0.0 Closure parameters should be on the same line as opening brace. ### Examples
Non Triggering Examples ```swift [1, 2].map { $0 + 1 } ``` ```swift [1, 2].map({ $0 + 1 }) ``` ```swift [1, 2].map { number in number + 1 } ``` ```swift [1, 2].map { number -> Int in number + 1 } ``` ```swift [1, 2].map { (number: Int) -> Int in number + 1 } ``` ```swift [1, 2].map { [weak self] number in number + 1 } ``` ```swift [1, 2].something(closure: { number in number + 1 }) ``` ```swift let isEmpty = [1, 2].isEmpty() ``` ```swift rlmConfiguration.migrationBlock.map { rlmMigration in return { migration, schemaVersion in rlmMigration(migration.rlmMigration, schemaVersion) } } ``` ```swift let mediaView: UIView = { [weak self] index in return UIView() }(index) ```
Triggering Examples ```swift [1, 2].map { ↓number in number + 1 } ``` ```swift [1, 2].map { ↓number -> Int in number + 1 } ``` ```swift [1, 2].map { (↓number: Int) -> Int in number + 1 } ``` ```swift [1, 2].map { [weak self] ↓number in number + 1 } ``` ```swift [1, 2].map { [weak self] ↓number in number + 1 } ``` ```swift [1, 2].map({ ↓number in number + 1 }) ``` ```swift [1, 2].something(closure: { ↓number in number + 1 }) ``` ```swift [1, 2].reduce(0) { ↓sum, ↓number in number + sum } ```
## Closure Spacing Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `closure_spacing` | Disabled | Yes | style | No | 3.0.0 Closure expressions should have a single space inside each brace. ### Examples
Non Triggering Examples ```swift [].map ({ $0.description }) ``` ```swift [].filter { $0.contains(location) } ``` ```swift extension UITableViewCell: ReusableView { } ``` ```swift extension UITableViewCell: ReusableView {} ```
Triggering Examples ```swift [].filter(↓{$0.contains(location)}) ``` ```swift [].map(↓{$0}) ``` ```swift (↓{each in return result.contains(where: ↓{e in return e}) }).count ``` ```swift filter ↓{ sorted ↓{ $0 < $1}} ```
## Colon Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `colon` | Enabled | Yes | style | No | 3.0.0 Colons should be next to the identifier when specifying a type and next to the key in dictionary literals. ### Examples
Non Triggering Examples ```swift let abc: Void ``` ```swift let abc: [Void: Void] ``` ```swift let abc: (Void, Void) ``` ```swift let abc: ([Void], String, Int) ``` ```swift let abc: [([Void], String, Int)] ``` ```swift let abc: String="def" ``` ```swift let abc: Int=0 ``` ```swift let abc: Enum=Enum.Value ``` ```swift func abc(def: Void) {} ``` ```swift func abc(def: Void, ghi: Void) {} ``` ```swift // 周斌佳年周斌佳 let abc: String = "abc:" ``` ```swift let abc = [Void: Void]() ``` ```swift let abc = [1: [3: 2], 3: 4] ``` ```swift let abc = ["string": "string"] ``` ```swift let abc = ["string:string": "string"] ``` ```swift let abc: [String: Int] ``` ```swift func foo(bar: [String: Int]) {} ``` ```swift func foo() -> [String: Int] { return [:] } ``` ```swift let abc: Any ``` ```swift let abc: [Any: Int] ``` ```swift let abc: [String: Any] ``` ```swift class Foo: Bar {} ``` ```swift class Foo {} ``` ```swift switch foo { case .bar: _ = something() } ``` ```swift object.method(x: 5, y: "string") ``` ```swift object.method(x: 5, y: "string") ``` ```swift object.method(5, y: "string") ``` ```swift func abc() { def(ghi: jkl) } ``` ```swift func abc(def: Void) { ghi(jkl: mno) } ``` ```swift class ABC { let def = ghi(jkl: mno) } } ``` ```swift func foo() { let dict = [1: 1] } ```
Triggering Examples ```swift let ↓abc:Void ``` ```swift let ↓abc: Void ``` ```swift let ↓abc :Void ``` ```swift let ↓abc : Void ``` ```swift let ↓abc : [Void: Void] ``` ```swift let ↓abc : (Void, String, Int) ``` ```swift let ↓abc : ([Void], String, Int) ``` ```swift let ↓abc : [([Void], String, Int)] ``` ```swift let ↓abc: (Void, String, Int) ``` ```swift let ↓abc: ([Void], String, Int) ``` ```swift let ↓abc: [([Void], String, Int)] ``` ```swift let ↓abc :String="def" ``` ```swift let ↓abc :Int=0 ``` ```swift let ↓abc :Int = 0 ``` ```swift let ↓abc:Int=0 ``` ```swift let ↓abc:Int = 0 ``` ```swift let ↓abc:Enum=Enum.Value ``` ```swift func abc(↓def:Void) {} ``` ```swift func abc(↓def: Void) {} ``` ```swift func abc(↓def :Void) {} ``` ```swift func abc(↓def : Void) {} ``` ```swift func abc(def: Void, ↓ghi :Void) {} ``` ```swift let abc = [Void↓:Void]() ``` ```swift let abc = [Void↓ : Void]() ``` ```swift let abc = [Void↓: Void]() ``` ```swift let abc = [Void↓ : Void]() ``` ```swift let abc = [1: [3↓ : 2], 3: 4] ``` ```swift let abc = [1: [3↓ : 2], 3↓: 4] ``` ```swift let abc: [↓String : Int] ``` ```swift let abc: [↓String:Int] ``` ```swift func foo(bar: [↓String : Int]) {} ``` ```swift func foo(bar: [↓String:Int]) {} ``` ```swift func foo() -> [↓String : Int] { return [:] } ``` ```swift func foo() -> [↓String:Int] { return [:] } ``` ```swift let ↓abc : Any ``` ```swift let abc: [↓Any : Int] ``` ```swift let abc: [↓String : Any] ``` ```swift class ↓Foo : Bar {} ``` ```swift class ↓Foo:Bar {} ``` ```swift class Foo<↓T:Equatable> {} ``` ```swift class Foo<↓T : Equatable> {} ``` ```swift object.method(x: 5, y↓ : "string") ``` ```swift object.method(x↓:5, y: "string") ``` ```swift object.method(x↓: 5, y: "string") ``` ```swift func abc() { def(ghi↓:jkl) } ``` ```swift func abc(def: Void) { ghi(jkl↓:mno) } ``` ```swift class ABC { let def = ghi(jkl↓:mno) } } ``` ```swift func foo() { let dict = [1↓ : 1] } ```
## Comma Spacing Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `comma` | Enabled | Yes | style | No | 3.0.0 There should be no space before and one after any comma. ### Examples
Non Triggering Examples ```swift func abc(a: String, b: String) { } ``` ```swift abc(a: "string", b: "string" ``` ```swift enum a { case a, b, c } ``` ```swift func abc( a: String, // comment bcd: String // comment ) { } ``` ```swift func abc( a: String, bcd: String ) { } ``` ```swift #imageLiteral(resourceName: "foo,bar,baz") ```
Triggering Examples ```swift func abc(a: String↓ ,b: String) { } ``` ```swift func abc(a: String↓ ,b: String↓ ,c: String↓ ,d: String) { } ``` ```swift abc(a: "string"↓,b: "string" ``` ```swift enum a { case a↓ ,b } ``` ```swift let result = plus( first: 3↓ , // #683 second: 4 ) ```
## Compiler Protocol Init Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `compiler_protocol_init` | Enabled | No | lint | No | 3.0.0 The initializers declared in compiler protocols such as `ExpressibleByArrayLiteral` shouldn't be called directly. ### Examples
Non Triggering Examples ```swift let set: Set = [1, 2] ``` ```swift let set = Set(array) ```
Triggering Examples ```swift let set = ↓Set(arrayLiteral: 1, 2) ``` ```swift let set = ↓Set.init(arrayLiteral: 1, 2) ```
## Conditional Returns on Newline Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `conditional_returns_on_newline` | Disabled | No | style | No | 3.0.0 Conditional statements should always return on the next line ### Examples
Non Triggering Examples ```swift guard true else { return true } ``` ```swift guard true, let x = true else { return true } ``` ```swift if true else { return true } ``` ```swift if true, let x = true else { return true } ``` ```swift if textField.returnKeyType == .Next { ``` ```swift if true { // return } ``` ```swift /*if true { */ return } ```
Triggering Examples ```swift ↓guard true else { return } ``` ```swift ↓if true { return } ``` ```swift ↓if true { break } else { return } ``` ```swift ↓if true { break } else { return } ``` ```swift ↓if true { return "YES" } else { return "NO" } ```
## Contains over first not nil Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `contains_over_first_not_nil` | Disabled | No | performance | No | 3.0.0 Prefer `contains` over `first(where:) != nil` ### Examples
Non Triggering Examples ```swift let first = myList.first(where: { $0 % 2 == 0 }) ``` ```swift let first = myList.first { $0 % 2 == 0 } ```
Triggering Examples ```swift ↓myList.first { $0 % 2 == 0 } != nil ``` ```swift ↓myList.first(where: { $0 % 2 == 0 }) != nil ``` ```swift ↓myList.map { $0 + 1 }.first(where: { $0 % 2 == 0 }) != nil ``` ```swift ↓myList.first(where: someFunction) != nil ``` ```swift ↓myList.map { $0 + 1 }.first { $0 % 2 == 0 } != nil ``` ```swift (↓myList.first { $0 % 2 == 0 }) != nil ```
## Control Statement Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `control_statement` | Enabled | No | style | No | 3.0.0 `if`, `for`, `guard`, `switch`, `while`, and `catch` statements shouldn't unnecessarily wrap their conditionals or arguments in parentheses. ### Examples
Non Triggering Examples ```swift if condition { ``` ```swift if (a, b) == (0, 1) { ``` ```swift if (a || b) && (c || d) { ``` ```swift if (min...max).contains(value) { ``` ```swift if renderGif(data) { ``` ```swift renderGif(data) ``` ```swift for item in collection { ``` ```swift for (key, value) in dictionary { ``` ```swift for (index, value) in enumerate(array) { ``` ```swift for var index = 0; index < 42; index++ { ``` ```swift guard condition else { ``` ```swift while condition { ``` ```swift } while condition { ``` ```swift do { ; } while condition { ``` ```swift switch foo { ``` ```swift do { } catch let error as NSError { } ``` ```swift foo().catch(all: true) {} ``` ```swift if max(a, b) < c { ``` ```swift switch (lhs, rhs) { ```
Triggering Examples ```swift ↓if (condition) { ``` ```swift ↓if(condition) { ``` ```swift ↓if (condition == endIndex) { ``` ```swift ↓if ((a || b) && (c || d)) { ``` ```swift ↓if ((min...max).contains(value)) { ``` ```swift ↓for (item in collection) { ``` ```swift ↓for (var index = 0; index < 42; index++) { ``` ```swift ↓for(item in collection) { ``` ```swift ↓for(var index = 0; index < 42; index++) { ``` ```swift ↓guard (condition) else { ``` ```swift ↓while (condition) { ``` ```swift ↓while(condition) { ``` ```swift } ↓while (condition) { ``` ```swift } ↓while(condition) { ``` ```swift do { ; } ↓while(condition) { ``` ```swift do { ; } ↓while (condition) { ``` ```swift ↓switch (foo) { ``` ```swift do { } ↓catch(let error as NSError) { } ``` ```swift ↓if (max(a, b) < c) { ```
## Convenience Type Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `convenience_type` | Disabled | No | idiomatic | No | 4.1.0 Types used for hosting only static members should be implemented as a caseless enum to avoid instantiation. ### Examples
Non Triggering Examples ```swift enum Math { // enum public static let pi = 3.14 } ``` ```swift // class with inheritance class MathViewController: UIViewController { public static let pi = 3.14 } ``` ```swift @objc class Math: NSObject { // class visible to Obj-C public static let pi = 3.14 } ``` ```swift struct Math { // type with non-static declarations public static let pi = 3.14 public let randomNumber = 2 } ``` ```swift class DummyClass {} ```
Triggering Examples ```swift ↓struct Math { public static let pi = 3.14 } ``` ```swift ↓class Math { public static let pi = 3.14 } ``` ```swift ↓struct Math { public static let pi = 3.14 @available(*, unavailable) init() {} } ```
## Custom Rules Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `custom_rules` | Enabled | No | style | No | 3.0.0 Create custom rules by providing a regex string. Optionally specify what syntax kinds to match against, the severity level, and what message to display. ## Cyclomatic Complexity Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `cyclomatic_complexity` | Enabled | No | metrics | No | 3.0.0 Complexity of function bodies should be limited. ### Examples
Non Triggering Examples ```swift func f1() { if true { for _ in 1..5 { } } if false { } } ``` ```swift func f(code: Int) -> Int {switch code { case 0: fallthrough case 0: return 1 case 0: return 1 case 0: return 1 case 0: return 1 case 0: return 1 case 0: return 1 case 0: return 1 case 0: return 1 default: return 1}} ``` ```swift func f1() {if true {}; if true {}; if true {}; if true {}; if true {}; if true {} func f2() { if true {}; if true {}; if true {}; if true {}; if true {} }} ```
Triggering Examples ```swift ↓func f1() { if true { if true { if false {} } } if false {} let i = 0 switch i { case 1: break case 2: break case 3: break case 4: break default: break } for _ in 1...5 { guard true else { return } } } ```
## Discarded Notification Center Observer Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `discarded_notification_center_observer` | Enabled | No | lint | No | 3.0.0 When registering for a notification using a block, the opaque observer that is returned should be stored so it can be removed later. ### Examples
Non Triggering Examples ```swift let foo = nc.addObserver(forName: .NSSystemTimeZoneDidChange, object: nil, queue: nil) { } ``` ```swift let foo = nc.addObserver(forName: .NSSystemTimeZoneDidChange, object: nil, queue: nil, using: { }) ``` ```swift func foo() -> Any { return nc.addObserver(forName: .NSSystemTimeZoneDidChange, object: nil, queue: nil, using: { }) } ```
Triggering Examples ```swift ↓nc.addObserver(forName: .NSSystemTimeZoneDidChange, object: nil, queue: nil) { } ``` ```swift ↓nc.addObserver(forName: .NSSystemTimeZoneDidChange, object: nil, queue: nil, using: { }) ``` ```swift @discardableResult func foo() -> Any { return ↓nc.addObserver(forName: .NSSystemTimeZoneDidChange, object: nil, queue: nil, using: { }) } ```
## Discouraged Direct Initialization Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `discouraged_direct_init` | Enabled | No | lint | No | 3.0.0 Discouraged direct initialization of types that can be harmful. ### Examples
Non Triggering Examples ```swift let foo = UIDevice.current ``` ```swift let foo = Bundle.main ``` ```swift let foo = Bundle(path: "bar") ``` ```swift let foo = Bundle(identifier: "bar") ``` ```swift let foo = Bundle.init(path: "bar") ``` ```swift let foo = Bundle.init(identifier: "bar") ```
Triggering Examples ```swift ↓UIDevice() ``` ```swift ↓Bundle() ``` ```swift let foo = ↓UIDevice() ``` ```swift let foo = ↓Bundle() ``` ```swift let foo = bar(bundle: ↓Bundle(), device: ↓UIDevice()) ``` ```swift ↓UIDevice.init() ``` ```swift ↓Bundle.init() ``` ```swift let foo = ↓UIDevice.init() ``` ```swift let foo = ↓Bundle.init() ``` ```swift let foo = bar(bundle: ↓Bundle.init(), device: ↓UIDevice.init()) ```
## Discouraged Object Literal Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `discouraged_object_literal` | Disabled | No | idiomatic | No | 3.0.0 Prefer initializers over object literals. ### Examples
Non Triggering Examples ```swift let image = UIImage(named: aVariable) ``` ```swift let image = UIImage(named: "interpolated \(variable)") ``` ```swift let color = UIColor(red: value, green: value, blue: value, alpha: 1) ``` ```swift let image = NSImage(named: aVariable) ``` ```swift let image = NSImage(named: "interpolated \(variable)") ``` ```swift let color = NSColor(red: value, green: value, blue: value, alpha: 1) ```
Triggering Examples ```swift let image = ↓#imageLiteral(resourceName: "image.jpg") ``` ```swift let color = ↓#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1) ```
## Discouraged Optional Boolean Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `discouraged_optional_boolean` | Disabled | No | idiomatic | No | 3.0.0 Prefer non-optional booleans over optional booleans. ### Examples
Non Triggering Examples ```swift var foo: Bool ``` ```swift var foo: [String: Bool] ``` ```swift var foo: [Bool] ``` ```swift let foo: Bool = true ``` ```swift let foo: Bool = false ``` ```swift let foo: [String: Bool] = [:] ``` ```swift let foo: [Bool] = [] ``` ```swift var foo: Bool { return true } ``` ```swift let foo: Bool { return false }() ``` ```swift func foo() -> Bool {} ``` ```swift func foo() -> [String: Bool] {} ``` ```swift func foo() -> ([Bool]) -> String {} ``` ```swift func foo(input: Bool = true) {} ``` ```swift func foo(input: [String: Bool] = [:]) {} ``` ```swift func foo(input: [Bool] = []) {} ``` ```swift class Foo { func foo() -> Bool {} } ``` ```swift class Foo { func foo() -> [String: Bool] {} } ``` ```swift class Foo { func foo() -> ([Bool]) -> String {} } ``` ```swift struct Foo { func foo() -> Bool {} } ``` ```swift struct Foo { func foo() -> [String: Bool] {} } ``` ```swift struct Foo { func foo() -> ([Bool]) -> String {} } ``` ```swift enum Foo { func foo() -> Bool {} } ``` ```swift enum Foo { func foo() -> [String: Bool] {} } ``` ```swift enum Foo { func foo() -> ([Bool]) -> String {} } ``` ```swift class Foo { func foo(input: Bool = true) {} } ``` ```swift class Foo { func foo(input: [String: Bool] = [:]) {} } ``` ```swift class Foo { func foo(input: [Bool] = []) {} } ``` ```swift struct Foo { func foo(input: Bool = true) {} } ``` ```swift struct Foo { func foo(input: [String: Bool] = [:]) {} } ``` ```swift struct Foo { func foo(input: [Bool] = []) {} } ``` ```swift enum Foo { func foo(input: Bool = true) {} } ``` ```swift enum Foo { func foo(input: [String: Bool] = [:]) {} } ``` ```swift enum Foo { func foo(input: [Bool] = []) {} } ```
Triggering Examples ```swift var foo: ↓Bool? ``` ```swift var foo: [String: ↓Bool?] ``` ```swift var foo: [↓Bool?] ``` ```swift let foo: ↓Bool? = nil ``` ```swift let foo: [String: ↓Bool?] = [:] ``` ```swift let foo: [↓Bool?] = [] ``` ```swift let foo = ↓Optional.some(false) ``` ```swift let foo = ↓Optional.some(true) ``` ```swift var foo: ↓Bool? { return nil } ``` ```swift let foo: ↓Bool? { return nil }() ``` ```swift func foo() -> ↓Bool? {} ``` ```swift func foo() -> [String: ↓Bool?] {} ``` ```swift func foo() -> [↓Bool?] {} ``` ```swift static func foo() -> ↓Bool? {} ``` ```swift static func foo() -> [String: ↓Bool?] {} ``` ```swift static func foo() -> [↓Bool?] {} ``` ```swift func foo() -> (↓Bool?) -> String {} ``` ```swift func foo() -> ([Int]) -> ↓Bool? {} ``` ```swift func foo(input: ↓Bool?) {} ``` ```swift func foo(input: [String: ↓Bool?]) {} ``` ```swift func foo(input: [↓Bool?]) {} ``` ```swift static func foo(input: ↓Bool?) {} ``` ```swift static func foo(input: [String: ↓Bool?]) {} ``` ```swift static func foo(input: [↓Bool?]) {} ``` ```swift class Foo { var foo: ↓Bool? } ``` ```swift class Foo { var foo: [String: ↓Bool?] } ``` ```swift class Foo { let foo: ↓Bool? = nil } ``` ```swift class Foo { let foo: [String: ↓Bool?] = [:] } ``` ```swift class Foo { let foo: [↓Bool?] = [] } ``` ```swift struct Foo { var foo: ↓Bool? } ``` ```swift struct Foo { var foo: [String: ↓Bool?] } ``` ```swift struct Foo { let foo: ↓Bool? = nil } ``` ```swift struct Foo { let foo: [String: ↓Bool?] = [:] } ``` ```swift struct Foo { let foo: [↓Bool?] = [] } ``` ```swift class Foo { var foo: ↓Bool? { return nil } } ``` ```swift class Foo { let foo: ↓Bool? { return nil }() } ``` ```swift struct Foo { var foo: ↓Bool? { return nil } } ``` ```swift struct Foo { let foo: ↓Bool? { return nil }() } ``` ```swift enum Foo { var foo: ↓Bool? { return nil } } ``` ```swift enum Foo { let foo: ↓Bool? { return nil }() } ``` ```swift class Foo { func foo() -> ↓Bool? {} } ``` ```swift class Foo { func foo() -> [String: ↓Bool?] {} } ``` ```swift class Foo { func foo() -> [↓Bool?] {} } ``` ```swift class Foo { static func foo() -> ↓Bool? {} } ``` ```swift class Foo { static func foo() -> [String: ↓Bool?] {} } ``` ```swift class Foo { static func foo() -> [↓Bool?] {} } ``` ```swift class Foo { func foo() -> (↓Bool?) -> String {} } ``` ```swift class Foo { func foo() -> ([Int]) -> ↓Bool? {} } ``` ```swift struct Foo { func foo() -> ↓Bool? {} } ``` ```swift struct Foo { func foo() -> [String: ↓Bool?] {} } ``` ```swift struct Foo { func foo() -> [↓Bool?] {} } ``` ```swift struct Foo { static func foo() -> ↓Bool? {} } ``` ```swift struct Foo { static func foo() -> [String: ↓Bool?] {} } ``` ```swift struct Foo { static func foo() -> [↓Bool?] {} } ``` ```swift struct Foo { func foo() -> (↓Bool?) -> String {} } ``` ```swift struct Foo { func foo() -> ([Int]) -> ↓Bool? {} } ``` ```swift enum Foo { func foo() -> ↓Bool? {} } ``` ```swift enum Foo { func foo() -> [String: ↓Bool?] {} } ``` ```swift enum Foo { func foo() -> [↓Bool?] {} } ``` ```swift enum Foo { static func foo() -> ↓Bool? {} } ``` ```swift enum Foo { static func foo() -> [String: ↓Bool?] {} } ``` ```swift enum Foo { static func foo() -> [↓Bool?] {} } ``` ```swift enum Foo { func foo() -> (↓Bool?) -> String {} } ``` ```swift enum Foo { func foo() -> ([Int]) -> ↓Bool? {} } ``` ```swift class Foo { func foo(input: ↓Bool?) {} } ``` ```swift class Foo { func foo(input: [String: ↓Bool?]) {} } ``` ```swift class Foo { func foo(input: [↓Bool?]) {} } ``` ```swift class Foo { static func foo(input: ↓Bool?) {} } ``` ```swift class Foo { static func foo(input: [String: ↓Bool?]) {} } ``` ```swift class Foo { static func foo(input: [↓Bool?]) {} } ``` ```swift struct Foo { func foo(input: ↓Bool?) {} } ``` ```swift struct Foo { func foo(input: [String: ↓Bool?]) {} } ``` ```swift struct Foo { func foo(input: [↓Bool?]) {} } ``` ```swift struct Foo { static func foo(input: ↓Bool?) {} } ``` ```swift struct Foo { static func foo(input: [String: ↓Bool?]) {} } ``` ```swift struct Foo { static func foo(input: [↓Bool?]) {} } ``` ```swift enum Foo { func foo(input: ↓Bool?) {} } ``` ```swift enum Foo { func foo(input: [String: ↓Bool?]) {} } ``` ```swift enum Foo { func foo(input: [↓Bool?]) {} } ``` ```swift enum Foo { static func foo(input: ↓Bool?) {} } ``` ```swift enum Foo { static func foo(input: [String: ↓Bool?]) {} } ``` ```swift enum Foo { static func foo(input: [↓Bool?]) {} } ```
## Discouraged Optional Collection Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `discouraged_optional_collection` | Disabled | No | idiomatic | No | 3.0.0 Prefer empty collection over optional collection. ### Examples
Non Triggering Examples ```swift var foo: [Int] ``` ```swift var foo: [String: Int] ``` ```swift var foo: Set ``` ```swift var foo: [String: [String: Int]] ``` ```swift let foo: [Int] = [] ``` ```swift let foo: [String: Int] = [:] ``` ```swift let foo: Set = [] ``` ```swift let foo: [String: [String: Int]] = [:] ``` ```swift var foo: [Int] { return [] } ``` ```swift func foo() -> [Int] {} ``` ```swift func foo() -> [String: String] {} ``` ```swift func foo() -> Set {} ``` ```swift func foo() -> ([Int]) -> String {} ``` ```swift func foo(input: [String] = []) {} ``` ```swift func foo(input: [String: String] = [:]) {} ``` ```swift func foo(input: Set = []) {} ``` ```swift class Foo { func foo() -> [Int] {} } ``` ```swift class Foo { func foo() -> [String: String] {} } ``` ```swift class Foo { func foo() -> Set {} } ``` ```swift class Foo { func foo() -> ([Int]) -> String {} } ``` ```swift struct Foo { func foo() -> [Int] {} } ``` ```swift struct Foo { func foo() -> [String: String] {} } ``` ```swift struct Foo { func foo() -> Set {} } ``` ```swift struct Foo { func foo() -> ([Int]) -> String {} } ``` ```swift enum Foo { func foo() -> [Int] {} } ``` ```swift enum Foo { func foo() -> [String: String] {} } ``` ```swift enum Foo { func foo() -> Set {} } ``` ```swift enum Foo { func foo() -> ([Int]) -> String {} } ``` ```swift class Foo { func foo(input: [String] = []) {} } ``` ```swift class Foo { func foo(input: [String: String] = [:]) {} } ``` ```swift class Foo { func foo(input: Set = []) {} } ``` ```swift struct Foo { func foo(input: [String] = []) {} } ``` ```swift struct Foo { func foo(input: [String: String] = [:]) {} } ``` ```swift struct Foo { func foo(input: Set = []) {} } ``` ```swift enum Foo { func foo(input: [String] = []) {} } ``` ```swift enum Foo { func foo(input: [String: String] = [:]) {} } ``` ```swift enum Foo { func foo(input: Set = []) {} } ```
Triggering Examples ```swift ↓var foo: [Int]? ``` ```swift ↓var foo: [String: Int]? ``` ```swift ↓var foo: Set? ``` ```swift ↓let foo: [Int]? = nil ``` ```swift ↓let foo: [String: Int]? = nil ``` ```swift ↓let foo: Set? = nil ``` ```swift ↓var foo: [Int]? { return nil } ``` ```swift ↓let foo: [Int]? { return nil }() ``` ```swift func ↓foo() -> [T]? {} ``` ```swift func ↓foo() -> [String: String]? {} ``` ```swift func ↓foo() -> [String: [String: String]]? {} ``` ```swift func ↓foo() -> [String: [String: String]?] {} ``` ```swift func ↓foo() -> Set? {} ``` ```swift static func ↓foo() -> [T]? {} ``` ```swift static func ↓foo() -> [String: String]? {} ``` ```swift static func ↓foo() -> [String: [String: String]]? {} ``` ```swift static func ↓foo() -> [String: [String: String]?] {} ``` ```swift static func ↓foo() -> Set? {} ``` ```swift func ↓foo() -> ([Int]?) -> String {} ``` ```swift func ↓foo() -> ([Int]) -> [String]? {} ``` ```swift func foo(↓input: [String: String]?) {} ``` ```swift func foo(↓input: [String: [String: String]]?) {} ``` ```swift func foo(↓input: [String: [String: String]?]) {} ``` ```swift func foo(↓↓input: [String: [String: String]?]?) {} ``` ```swift func foo(_ dict1: [K: V], ↓_ dict2: [K: V]?) -> [K: V] ``` ```swift func foo(dict1: [K: V], ↓dict2: [K: V]?) -> [K: V] ``` ```swift static func foo(↓input: [String: String]?) {} ``` ```swift static func foo(↓input: [String: [String: String]]?) {} ``` ```swift static func foo(↓input: [String: [String: String]?]) {} ``` ```swift static func foo(↓↓input: [String: [String: String]?]?) {} ``` ```swift static func foo(_ dict1: [K: V], ↓_ dict2: [K: V]?) -> [K: V] ``` ```swift static func foo(dict1: [K: V], ↓dict2: [K: V]?) -> [K: V] ``` ```swift class Foo { ↓var foo: [Int]? } ``` ```swift class Foo { ↓var foo: [String: Int]? } ``` ```swift class Foo { ↓var foo: Set? } ``` ```swift class Foo { ↓let foo: [Int]? = nil } ``` ```swift class Foo { ↓let foo: [String: Int]? = nil } ``` ```swift class Foo { ↓let foo: Set? = nil } ``` ```swift struct Foo { ↓var foo: [Int]? } ``` ```swift struct Foo { ↓var foo: [String: Int]? } ``` ```swift struct Foo { ↓var foo: Set? } ``` ```swift struct Foo { ↓let foo: [Int]? = nil } ``` ```swift struct Foo { ↓let foo: [String: Int]? = nil } ``` ```swift struct Foo { ↓let foo: Set? = nil } ``` ```swift class Foo { ↓var foo: [Int]? { return nil } } ``` ```swift class Foo { ↓let foo: [Int]? { return nil }() } ``` ```swift class Foo { ↓var foo: Set? { return nil } } ``` ```swift class Foo { ↓let foo: Set? { return nil }() } ``` ```swift struct Foo { ↓var foo: [Int]? { return nil } } ``` ```swift struct Foo { ↓let foo: [Int]? { return nil }() } ``` ```swift struct Foo { ↓var foo: Set? { return nil } } ``` ```swift struct Foo { ↓let foo: Set? { return nil }() } ``` ```swift enum Foo { ↓var foo: [Int]? { return nil } } ``` ```swift enum Foo { ↓let foo: [Int]? { return nil }() } ``` ```swift enum Foo { ↓var foo: Set? { return nil } } ``` ```swift enum Foo { ↓let foo: Set? { return nil }() } ``` ```swift class Foo { func ↓foo() -> [T]? {} } ``` ```swift class Foo { func ↓foo() -> [String: String]? {} } ``` ```swift class Foo { func ↓foo() -> [String: [String: String]]? {} } ``` ```swift class Foo { func ↓foo() -> [String: [String: String]?] {} } ``` ```swift class Foo { func ↓foo() -> Set? {} } ``` ```swift class Foo { static func ↓foo() -> [T]? {} } ``` ```swift class Foo { static func ↓foo() -> [String: String]? {} } ``` ```swift class Foo { static func ↓foo() -> [String: [String: String]]? {} } ``` ```swift class Foo { static func ↓foo() -> [String: [String: String]?] {} } ``` ```swift class Foo { static func ↓foo() -> Set? {} } ``` ```swift class Foo { func ↓foo() -> ([Int]?) -> String {} } ``` ```swift class Foo { func ↓foo() -> ([Int]) -> [String]? {} } ``` ```swift struct Foo { func ↓foo() -> [T]? {} } ``` ```swift struct Foo { func ↓foo() -> [String: String]? {} } ``` ```swift struct Foo { func ↓foo() -> [String: [String: String]]? {} } ``` ```swift struct Foo { func ↓foo() -> [String: [String: String]?] {} } ``` ```swift struct Foo { func ↓foo() -> Set? {} } ``` ```swift struct Foo { static func ↓foo() -> [T]? {} } ``` ```swift struct Foo { static func ↓foo() -> [String: String]? {} } ``` ```swift struct Foo { static func ↓foo() -> [String: [String: String]]? {} } ``` ```swift struct Foo { static func ↓foo() -> [String: [String: String]?] {} } ``` ```swift struct Foo { static func ↓foo() -> Set? {} } ``` ```swift struct Foo { func ↓foo() -> ([Int]?) -> String {} } ``` ```swift struct Foo { func ↓foo() -> ([Int]) -> [String]? {} } ``` ```swift enum Foo { func ↓foo() -> [T]? {} } ``` ```swift enum Foo { func ↓foo() -> [String: String]? {} } ``` ```swift enum Foo { func ↓foo() -> [String: [String: String]]? {} } ``` ```swift enum Foo { func ↓foo() -> [String: [String: String]?] {} } ``` ```swift enum Foo { func ↓foo() -> Set? {} } ``` ```swift enum Foo { static func ↓foo() -> [T]? {} } ``` ```swift enum Foo { static func ↓foo() -> [String: String]? {} } ``` ```swift enum Foo { static func ↓foo() -> [String: [String: String]]? {} } ``` ```swift enum Foo { static func ↓foo() -> [String: [String: String]?] {} } ``` ```swift enum Foo { static func ↓foo() -> Set? {} } ``` ```swift enum Foo { func ↓foo() -> ([Int]?) -> String {} } ``` ```swift enum Foo { func ↓foo() -> ([Int]) -> [String]? {} } ``` ```swift class Foo { func foo(↓input: [String: String]?) {} } ``` ```swift class Foo { func foo(↓input: [String: [String: String]]?) {} } ``` ```swift class Foo { func foo(↓input: [String: [String: String]?]) {} } ``` ```swift class Foo { func foo(↓↓input: [String: [String: String]?]?) {} } ``` ```swift class Foo { func foo(_ dict1: [K: V], ↓_ dict2: [K: V]?) -> [K: V] } ``` ```swift class Foo { func foo(dict1: [K: V], ↓dict2: [K: V]?) -> [K: V] } ``` ```swift class Foo { static func foo(↓input: [String: String]?) {} } ``` ```swift class Foo { static func foo(↓input: [String: [String: String]]?) {} } ``` ```swift class Foo { static func foo(↓input: [String: [String: String]?]) {} } ``` ```swift class Foo { static func foo(↓↓input: [String: [String: String]?]?) {} } ``` ```swift class Foo { static func foo(_ dict1: [K: V], ↓_ dict2: [K: V]?) -> [K: V] } ``` ```swift class Foo { static func foo(dict1: [K: V], ↓dict2: [K: V]?) -> [K: V] } ``` ```swift struct Foo { func foo(↓input: [String: String]?) {} } ``` ```swift struct Foo { func foo(↓input: [String: [String: String]]?) {} } ``` ```swift struct Foo { func foo(↓input: [String: [String: String]?]) {} } ``` ```swift struct Foo { func foo(↓↓input: [String: [String: String]?]?) {} } ``` ```swift struct Foo { func foo(_ dict1: [K: V], ↓_ dict2: [K: V]?) -> [K: V] } ``` ```swift struct Foo { func foo(dict1: [K: V], ↓dict2: [K: V]?) -> [K: V] } ``` ```swift struct Foo { static func foo(↓input: [String: String]?) {} } ``` ```swift struct Foo { static func foo(↓input: [String: [String: String]]?) {} } ``` ```swift struct Foo { static func foo(↓input: [String: [String: String]?]) {} } ``` ```swift struct Foo { static func foo(↓↓input: [String: [String: String]?]?) {} } ``` ```swift struct Foo { static func foo(_ dict1: [K: V], ↓_ dict2: [K: V]?) -> [K: V] } ``` ```swift struct Foo { static func foo(dict1: [K: V], ↓dict2: [K: V]?) -> [K: V] } ``` ```swift enum Foo { func foo(↓input: [String: String]?) {} } ``` ```swift enum Foo { func foo(↓input: [String: [String: String]]?) {} } ``` ```swift enum Foo { func foo(↓input: [String: [String: String]?]) {} } ``` ```swift enum Foo { func foo(↓↓input: [String: [String: String]?]?) {} } ``` ```swift enum Foo { func foo(_ dict1: [K: V], ↓_ dict2: [K: V]?) -> [K: V] } ``` ```swift enum Foo { func foo(dict1: [K: V], ↓dict2: [K: V]?) -> [K: V] } ``` ```swift enum Foo { static func foo(↓input: [String: String]?) {} } ``` ```swift enum Foo { static func foo(↓input: [String: [String: String]]?) {} } ``` ```swift enum Foo { static func foo(↓input: [String: [String: String]?]) {} } ``` ```swift enum Foo { static func foo(↓↓input: [String: [String: String]?]?) {} } ``` ```swift enum Foo { static func foo(_ dict1: [K: V], ↓_ dict2: [K: V]?) -> [K: V] } ``` ```swift enum Foo { static func foo(dict1: [K: V], ↓dict2: [K: V]?) -> [K: V] } ```
## Dynamic Inline Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `dynamic_inline` | Enabled | No | lint | No | 3.0.0 Avoid using 'dynamic' and '@inline(__always)' together. ### Examples
Non Triggering Examples ```swift class C { dynamic func f() {}} ``` ```swift class C { @inline(__always) func f() {}} ``` ```swift class C { @inline(never) dynamic func f() {}} ```
Triggering Examples ```swift class C { @inline(__always) dynamic ↓func f() {} } ``` ```swift class C { @inline(__always) public dynamic ↓func f() {} } ``` ```swift class C { @inline(__always) dynamic internal ↓func f() {} } ``` ```swift class C { @inline(__always) dynamic ↓func f() {} } ``` ```swift class C { @inline(__always) dynamic ↓func f() {} } ```
## Empty Count Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `empty_count` | Disabled | No | performance | No | 3.0.0 Prefer checking `isEmpty` over comparing `count` to zero. ### Examples
Non Triggering Examples ```swift var count = 0 ``` ```swift [Int]().isEmpty ``` ```swift [Int]().count > 1 ``` ```swift [Int]().count == 1 ``` ```swift discount == 0 ``` ```swift order.discount == 0 ```
Triggering Examples ```swift [Int]().↓count == 0 ``` ```swift [Int]().↓count > 0 ``` ```swift [Int]().↓count != 0 ``` ```swift ↓count == 0 ```
## Empty Enum Arguments Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `empty_enum_arguments` | Enabled | Yes | style | No | 3.0.0 Arguments can be omitted when matching enums with associated types if they are not used. ### Examples
Non Triggering Examples ```swift switch foo { case .bar: break } ``` ```swift switch foo { case .bar(let x): break } ``` ```swift switch foo { case let .bar(x): break } ``` ```swift switch (foo, bar) { case (_, _): break } ``` ```swift switch foo { case "bar".uppercased(): break } ``` ```swift switch (foo, bar) { case (_, _) where !something: break } ``` ```swift switch foo { case (let f as () -> String)?: break } ``` ```swift switch foo { default: break } ```
Triggering Examples ```swift switch foo { case .bar↓(_): break } ``` ```swift switch foo { case .bar↓(): break } ``` ```swift switch foo { case .bar↓(_), .bar2↓(_): break } ``` ```swift switch foo { case .bar↓() where method() > 2: break } ``` ```swift func example(foo: Foo) { switch foo { case case .bar↓(_): break } } ```
## Empty Parameters Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `empty_parameters` | Enabled | Yes | style | No | 3.0.0 Prefer `() -> ` over `Void -> `. ### Examples
Non Triggering Examples ```swift let abc: () -> Void = {} ``` ```swift func foo(completion: () -> Void) ``` ```swift func foo(completion: () thows -> Void) ``` ```swift let foo: (ConfigurationTests) -> Void throws -> Void) ``` ```swift let foo: (ConfigurationTests) -> Void throws -> Void) ``` ```swift let foo: (ConfigurationTests) ->Void throws -> Void) ```
Triggering Examples ```swift let abc: ↓(Void) -> Void = {} ``` ```swift func foo(completion: ↓(Void) -> Void) ``` ```swift func foo(completion: ↓(Void) throws -> Void) ``` ```swift let foo: ↓(Void) -> () throws -> Void) ```
## Empty Parentheses with Trailing Closure Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `empty_parentheses_with_trailing_closure` | Enabled | Yes | style | No | 3.0.0 When using trailing closures, empty parentheses should be avoided after the method call. ### Examples
Non Triggering Examples ```swift [1, 2].map { $0 + 1 } ``` ```swift [1, 2].map({ $0 + 1 }) ``` ```swift [1, 2].reduce(0) { $0 + $1 } ``` ```swift [1, 2].map { number in number + 1 } ``` ```swift let isEmpty = [1, 2].isEmpty() ``` ```swift UIView.animateWithDuration(0.3, animations: { self.disableInteractionRightView.alpha = 0 }, completion: { _ in () }) ```
Triggering Examples ```swift [1, 2].map↓() { $0 + 1 } ``` ```swift [1, 2].map↓( ) { $0 + 1 } ``` ```swift [1, 2].map↓() { number in number + 1 } ``` ```swift [1, 2].map↓( ) { number in number + 1 } ``` ```swift func foo() -> [Int] { return [1, 2].map↓() { $0 + 1 } } ```
## Empty String Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `empty_string` | Disabled | No | performance | No | 3.0.0 Prefer checking `isEmpty` over comparing `string` to an empty string literal. ### Examples
Non Triggering Examples ```swift myString.isEmpty ``` ```swift !myString.isEmpy ```
Triggering Examples ```swift myString↓ == "" ``` ```swift myString↓ != "" ```
## Empty XCTest Method Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `empty_xctest_method` | Disabled | No | lint | No | 3.0.0 Empty XCTest method should be avoided. ### Examples
Non Triggering Examples ```swift class TotoTests: XCTestCase { var foobar: Foobar? override func setUp() { super.setUp() foobar = Foobar() } override func tearDown() { foobar = nil super.tearDown() } func testFoo() { XCTAssertTrue(foobar?.foo) } func testBar() { // comment... XCTAssertFalse(foobar?.bar) // comment... } } ``` ```swift class Foobar { func setUp() {} func tearDown() {} func testFoo() {} } ``` ```swift class TotoTests: XCTestCase { func setUp(with object: Foobar) {} func tearDown(object: Foobar) {} func testFoo(_ foo: Foobar) {} func testBar(bar: (String) -> Int) {} } ``` ```swift class TotoTests: XCTestCase { func testFoo() { XCTAssertTrue(foobar?.foo) } func testBar() { XCTAssertFalse(foobar?.bar) } } ```
Triggering Examples ```swift class TotoTests: XCTestCase { override ↓func setUp() { } override ↓func tearDown() { } ↓func testFoo() { } ↓func testBar() { } func helperFunction() { } } ``` ```swift class TotoTests: XCTestCase { override ↓func setUp() {} override ↓func tearDown() {} ↓func testFoo() {} func helperFunction() {} } ``` ```swift class TotoTests: XCTestCase { override ↓func setUp() { // comment... } override ↓func tearDown() { // comment... // comment... } ↓func testFoo() { // comment... // comment... // comment... } ↓func testBar() { /* * comment... * * comment... * * comment... */ } func helperFunction() { } } ``` ```swift class FooTests: XCTestCase { override ↓func setUp() {} } class BarTests: XCTestCase { ↓func testFoo() {} } ```
## Explicit ACL Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `explicit_acl` | Disabled | No | idiomatic | No | 3.0.0 All declarations should specify Access Control Level keywords explicitly. ### Examples
Non Triggering Examples ```swift internal enum A {} ``` ```swift public final class B {} ``` ```swift private struct C {} ``` ```swift internal enum A { internal enum B {} } ``` ```swift internal final class Foo {} ``` ```swift internal class Foo { private let bar = 5 } ``` ```swift internal func a() { let a = } ``` ```swift private func a() { func innerFunction() { } } ``` ```swift private enum Foo { enum Bar { } } ``` ```swift private struct C { let d = 5 } ``` ```swift internal protocol A { func b() } ``` ```swift internal protocol A { var b: Int } ``` ```swift internal class A { deinit {} } ```
Triggering Examples ```swift enum A {} ``` ```swift final class B {} ``` ```swift internal struct C { let d = 5 } ``` ```swift public struct C { let d = 5 } ``` ```swift func a() {} ``` ```swift internal let a = 0 func b() {} ```
## Explicit Enum Raw Value Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `explicit_enum_raw_value` | Disabled | No | idiomatic | No | 3.0.0 Enums should be explicitly assigned their raw values. ### Examples
Non Triggering Examples ```swift enum Numbers { case int(Int) case short(Int16) } ``` ```swift enum Numbers: Int { case one = 1 case two = 2 } ``` ```swift enum Numbers: Double { case one = 1.1 case two = 2.2 } ``` ```swift enum Numbers: String { case one = "one" case two = "two" } ``` ```swift protocol Algebra {} enum Numbers: Algebra { case one } ```
Triggering Examples ```swift enum Numbers: Int { case one = 10, ↓two, three = 30 } ``` ```swift enum Numbers: NSInteger { case ↓one } ``` ```swift enum Numbers: String { case ↓one case ↓two } ``` ```swift enum Numbers: String { case ↓one, two = "two" } ``` ```swift enum Numbers: Decimal { case ↓one, ↓two } ```
## Explicit Init Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `explicit_init` | Disabled | Yes | idiomatic | No | 3.0.0 Explicitly calling .init() should be avoided. ### Examples
Non Triggering Examples ```swift import Foundation; class C: NSObject { override init() { super.init() }} ``` ```swift struct S { let n: Int }; extension S { init() { self.init(n: 1) } } ``` ```swift [1].flatMap(String.init) ``` ```swift [String.self].map { $0.init(1) } ``` ```swift [String.self].map { type in type.init(1) } ```
Triggering Examples ```swift [1].flatMap{String↓.init($0)} ``` ```swift [String.self].map { Type in Type↓.init(1) } ``` ```swift func foo() -> [String] { return [1].flatMap { String↓.init($0) } } ```
## Explicit Self Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `explicit_self` | Disabled | Yes | style | Yes | 3.0.0 Instance variables and functions should be explicitly accessed with 'self.'. ### Examples
Non Triggering Examples ```swift struct A { func f1() {} func f2() { self.f1() } } ``` ```swift struct A { let p1: Int func f1() { _ = self.p1 } } ```
Triggering Examples ```swift struct A { func f1() {} func f2() { ↓f1() } } ``` ```swift struct A { let p1: Int func f1() { _ = ↓p1 } } ```
## Explicit Top Level ACL Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `explicit_top_level_acl` | Disabled | No | idiomatic | No | 3.0.0 Top-level declarations should specify Access Control Level keywords explicitly. ### Examples
Non Triggering Examples ```swift internal enum A {} ``` ```swift public final class B {} ``` ```swift private struct C {} ``` ```swift internal enum A { enum B {} } ``` ```swift internal final class Foo {} ``` ```swift internal class Foo {} ``` ```swift internal func a() {} ```
Triggering Examples ```swift enum A {} ``` ```swift final class B {} ``` ```swift struct C {} ``` ```swift func a() {} ``` ```swift internal let a = 0 func b() {} ```
## Explicit Type Interface Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `explicit_type_interface` | Disabled | No | idiomatic | No | 3.0.0 Properties should have a type interface ### Examples
Non Triggering Examples ```swift class Foo { var myVar: Int? = 0 } ``` ```swift class Foo { let myVar: Int? = 0 } ``` ```swift class Foo { static var myVar: Int? = 0 } ``` ```swift class Foo { class var myVar: Int? = 0 } ```
Triggering Examples ```swift class Foo { ↓var myVar = 0 } ``` ```swift class Foo { ↓let mylet = 0 } ``` ```swift class Foo { ↓static var myStaticVar = 0 } ``` ```swift class Foo { ↓class var myClassVar = 0 } ``` ```swift class Foo { ↓let myVar = Int(0) } ``` ```swift class Foo { ↓let myVar = Set(0) } ```
## Extension Access Modifier Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `extension_access_modifier` | Disabled | No | idiomatic | No | 3.0.0 Prefer to use extension access modifiers ### Examples
Non Triggering Examples ```swift extension Foo: SomeProtocol { public var bar: Int { return 1 } } ``` ```swift extension Foo { private var bar: Int { return 1 } public var baz: Int { return 1 } } ``` ```swift extension Foo { private var bar: Int { return 1 } public func baz() {} } ``` ```swift extension Foo { var bar: Int { return 1 } var baz: Int { return 1 } } ``` ```swift public extension Foo { var bar: Int { return 1 } var baz: Int { return 1 } } ``` ```swift extension Foo { private bar: Int { return 1 } private baz: Int { return 1 } } ``` ```swift extension Foo { open bar: Int { return 1 } open baz: Int { return 1 } } ```
Triggering Examples ```swift ↓extension Foo { public var bar: Int { return 1 } public var baz: Int { return 1 } } ``` ```swift ↓extension Foo { public var bar: Int { return 1 } public func baz() {} } ``` ```swift public extension Foo { public ↓func bar() {} public ↓func baz() {} } ```
## Fallthrough Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `fallthrough` | Disabled | No | idiomatic | No | 3.0.0 Fallthrough should be avoided. ### Examples
Non Triggering Examples ```swift switch foo { case .bar, .bar2, .bar3: something() } ```
Triggering Examples ```swift switch foo { case .bar: ↓fallthrough case .bar2: something() } ```
## Fatal Error Message Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `fatal_error_message` | Disabled | No | idiomatic | No | 3.0.0 A fatalError call should have a message. ### Examples
Non Triggering Examples ```swift func foo() { fatalError("Foo") } ``` ```swift func foo() { fatalError(x) } ```
Triggering Examples ```swift func foo() { ↓fatalError("") } ``` ```swift func foo() { ↓fatalError() } ```
## File Header Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `file_header` | Disabled | No | style | No | 3.0.0 Header comments should be consistent with project patterns. The SWIFTLINT_CURRENT_FILENAME placeholder can optionally be used in the required and forbidden patterns. It will be replaced by the real file name. ### Examples
Non Triggering Examples ```swift let foo = "Copyright" ``` ```swift let foo = 2 // Copyright ``` ```swift let foo = 2 // Copyright ```
Triggering Examples ```swift // ↓Copyright ``` ```swift // // ↓Copyright ``` ```swift // // FileHeaderRule.swift // SwiftLint // // Created by Marcelo Fabri on 27/11/16. // ↓Copyright © 2016 Realm. All rights reserved. // ```
## File Line Length Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `file_length` | Enabled | No | metrics | No | 3.0.0 Files should not span too many lines. ### Examples
Non Triggering Examples ```swift print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") ```
Triggering Examples ```swift print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") ``` ```swift print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") print("swiftlint") // ```
## File Name Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `file_name` | Disabled | No | idiomatic | No | 3.0.0 File name should match a type or extension declared in the file (if any). ## First Where Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `first_where` | Disabled | No | performance | No | 3.0.0 Prefer using `.first(where:)` over `.filter { }.first` in collections. ### Examples
Non Triggering Examples ```swift kinds.filter(excludingKinds.contains).isEmpty && kinds.first == .identifier ``` ```swift myList.first(where: { $0 % 2 == 0 }) ``` ```swift match(pattern: pattern).filter { $0.first == .identifier } ``` ```swift (myList.filter { $0 == 1 }.suffix(2)).first ```
Triggering Examples ```swift ↓myList.filter { $0 % 2 == 0 }.first ``` ```swift ↓myList.filter({ $0 % 2 == 0 }).first ``` ```swift ↓myList.map { $0 + 1 }.filter({ $0 % 2 == 0 }).first ``` ```swift ↓myList.map { $0 + 1 }.filter({ $0 % 2 == 0 }).first?.something() ``` ```swift ↓myList.filter(someFunction).first ``` ```swift ↓myList.filter({ $0 % 2 == 0 }) .first ``` ```swift (↓myList.filter { $0 == 1 }).first ```
## For Where Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `for_where` | Enabled | No | idiomatic | No | 3.0.0 `where` clauses are preferred over a single `if` inside a `for`. ### Examples
Non Triggering Examples ```swift for user in users where user.id == 1 { } ``` ```swift for user in users { if let id = user.id { } } ``` ```swift for user in users { if var id = user.id { } } ``` ```swift for user in users { if user.id == 1 { } else { } } ``` ```swift for user in users { if user.id == 1 { } else if user.id == 2 { } } ``` ```swift for user in users { if user.id == 1 { } print(user) } ``` ```swift for user in users { let id = user.id if id == 1 { } } ``` ```swift for user in users { if user.id == 1 { } return true } ``` ```swift for user in users { if user.id == 1 && user.age > 18 { } } ``` ```swift for (index, value) in array.enumerated() { if case .valueB(_) = value { return index } } ```
Triggering Examples ```swift for user in users { ↓if user.id == 1 { return true } } ```
## Force Cast Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `force_cast` | Enabled | No | idiomatic | No | 3.0.0 Force casts should be avoided. ### Examples
Non Triggering Examples ```swift NSNumber() as? Int ```
Triggering Examples ```swift NSNumber() ↓as! Int ```
## Force Try Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `force_try` | Enabled | No | idiomatic | No | 3.0.0 Force tries should be avoided. ### Examples
Non Triggering Examples ```swift func a() throws {}; do { try a() } catch {} ```
Triggering Examples ```swift func a() throws {}; ↓try! a() ```
## Force Unwrapping Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `force_unwrapping` | Disabled | No | idiomatic | No | 3.0.0 Force unwrapping should be avoided. ### Examples
Non Triggering Examples ```swift if let url = NSURL(string: query) ``` ```swift navigationController?.pushViewController(viewController, animated: true) ``` ```swift let s as! Test ``` ```swift try! canThrowErrors() ``` ```swift let object: Any! ``` ```swift @IBOutlet var constraints: [NSLayoutConstraint]! ``` ```swift setEditing(!editing, animated: true) ``` ```swift navigationController.setNavigationBarHidden(!navigationController.navigationBarHidden, animated: true) ``` ```swift if addedToPlaylist && (!self.selectedFilters.isEmpty || self.searchBar?.text?.isEmpty == false) {} ``` ```swift print("\(xVar)!") ``` ```swift var test = (!bar) ``` ```swift var a: [Int]! ``` ```swift private var myProperty: (Void -> Void)! ``` ```swift func foo(_ options: [AnyHashable: Any]!) { ``` ```swift func foo() -> [Int]! ``` ```swift func foo() -> [AnyHashable: Any]! ``` ```swift func foo() -> [Int]! { return [] } ```
Triggering Examples ```swift let url = NSURL(string: query)↓! ``` ```swift navigationController↓!.pushViewController(viewController, animated: true) ``` ```swift let unwrapped = optional↓! ``` ```swift return cell↓! ``` ```swift let url = NSURL(string: "http://www.google.com")↓! ``` ```swift let dict = ["Boooo": "👻"]func bla() -> String { return dict["Boooo"]↓! } ``` ```swift let dict = ["Boooo": "👻"]func bla() -> String { return dict["Boooo"]↓!.contains("B") } ``` ```swift let a = dict["abc"]↓!.contains("B") ``` ```swift dict["abc"]↓!.bar("B") ``` ```swift if dict["a"]↓!!!! { ``` ```swift var foo: [Bool]! = dict["abc"]↓! ``` ```swift context("abc") { var foo: [Bool]! = dict["abc"]↓! } ``` ```swift open var computed: String { return foo.bar↓! } ```
## Function Body Length Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `function_body_length` | Enabled | No | metrics | No | 3.0.0 Functions bodies should not span too many lines. ## Function Default Parameter at End Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `function_default_parameter_at_end` | Disabled | No | idiomatic | No | 3.0.0 Prefer to locate parameters with defaults toward the end of the parameter list. ### Examples
Non Triggering Examples ```swift func foo(baz: String, bar: Int = 0) {} ``` ```swift func foo(x: String, y: Int = 0, z: CGFloat = 0) {} ``` ```swift func foo(bar: String, baz: Int = 0, z: () -> Void) {} ``` ```swift func foo(bar: String, z: () -> Void, baz: Int = 0) {} ``` ```swift func foo(bar: Int = 0) {} ``` ```swift func foo() {} ``` ```swift class A: B { override func foo(bar: Int = 0, baz: String) {} ``` ```swift func foo(bar: Int = 0, completion: @escaping CompletionHandler) {} ``` ```swift func foo(a: Int, b: CGFloat = 0) { let block = { (error: Error?) in } } ```
Triggering Examples ```swift ↓func foo(bar: Int = 0, baz: String) {} ```
## Function Parameter Count Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `function_parameter_count` | Enabled | No | metrics | No | 3.0.0 Number of function parameters should be low. ### Examples
Non Triggering Examples ```swift init(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) {} ``` ```swift init (a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) {} ``` ```swift `init`(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) {} ``` ```swift init?(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) {} ``` ```swift init?(a: T, b: Int, c: Int, d: Int, e: Int, f: Int) {} ``` ```swift init?(a: T, b: Int, c: Int, d: Int, e: Int, f: Int) {} ``` ```swift func f2(p1: Int, p2: Int) { } ``` ```swift func f(a: Int, b: Int, c: Int, d: Int, x: Int = 42) {} ``` ```swift func f(a: [Int], b: Int, c: Int, d: Int, f: Int) -> [Int] { let s = a.flatMap { $0 as? [String: Int] } ?? []}} ``` ```swift override func f(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) {} ```
Triggering Examples ```swift ↓func f(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) {} ``` ```swift ↓func initialValue(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) {} ``` ```swift ↓func f(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int = 2, g: Int) {} ``` ```swift struct Foo { init(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) {} ↓func bar(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) {}} ```
## Generic Type Name Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `generic_type_name` | Enabled | No | idiomatic | No | 3.0.0 Generic type name should only contain alphanumeric characters, start with an uppercase character and span between 1 and 20 characters in length. ### Examples
Non Triggering Examples ```swift func foo() {} ``` ```swift func foo() -> T {} ``` ```swift func foo(param: U) -> T {} ``` ```swift func foo(param: U) -> T {} ``` ```swift struct Foo {} ``` ```swift class Foo {} ``` ```swift enum Foo {} ``` ```swift func run(_ options: NoOptions>) {} ``` ```swift func foo(_ options: Set) {} ``` ```swift func < (lhs: T?, rhs: T?) -> Bool ``` ```swift func configureWith(data: Either) ``` ```swift typealias StringDictionary = Dictionary ``` ```swift typealias BackwardTriple = (T3, T2, T1) ``` ```swift typealias DictionaryOfStrings = Dictionary ```
Triggering Examples ```swift func foo<↓T_Foo>() {} ``` ```swift func foo(param: U_Foo) -> T {} ``` ```swift func foo<↓TTTTTTTTTTTTTTTTTTTTT>() {} ``` ```swift func foo<↓type>() {} ``` ```swift typealias StringDictionary<↓T_Foo> = Dictionary ``` ```swift typealias BackwardTriple = (T3, T2_Bar, T1) ``` ```swift typealias DictionaryOfStrings<↓T_Foo: Hashable> = Dictionary ``` ```swift class Foo<↓T_Foo> {} ``` ```swift class Foo {} ``` ```swift class Foo<↓T_Foo, ↓U_Foo> {} ``` ```swift class Foo<↓TTTTTTTTTTTTTTTTTTTTT> {} ``` ```swift class Foo<↓type> {} ``` ```swift struct Foo<↓T_Foo> {} ``` ```swift struct Foo {} ``` ```swift struct Foo<↓T_Foo, ↓U_Foo> {} ``` ```swift struct Foo<↓TTTTTTTTTTTTTTTTTTTTT> {} ``` ```swift struct Foo<↓type> {} ``` ```swift enum Foo<↓T_Foo> {} ``` ```swift enum Foo {} ``` ```swift enum Foo<↓T_Foo, ↓U_Foo> {} ``` ```swift enum Foo<↓TTTTTTTTTTTTTTTTTTTTT> {} ``` ```swift enum Foo<↓type> {} ```
## Identifier Name Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `identifier_name` | Enabled | No | style | No | 3.0.0 Identifier names should only contain alphanumeric characters and start with a lowercase character or should only contain capital letters. In an exception to the above, variable names may start with a capital letter when they are declared static and immutable. Variable names should not be too long or too short. ### Examples
Non Triggering Examples ```swift let myLet = 0 ``` ```swift var myVar = 0 ``` ```swift private let _myLet = 0 ``` ```swift class Abc { static let MyLet = 0 } ``` ```swift let URL: NSURL? = nil ``` ```swift let XMLString: String? = nil ``` ```swift override var i = 0 ``` ```swift enum Foo { case myEnum } ``` ```swift func isOperator(name: String) -> Bool ``` ```swift func typeForKind(_ kind: SwiftDeclarationKind) -> String ``` ```swift func == (lhs: SyntaxToken, rhs: SyntaxToken) -> Bool ``` ```swift override func IsOperator(name: String) -> Bool ``` ```swift enum Foo { case `private` } ``` ```swift enum Foo { case value(String) } ```
Triggering Examples ```swift ↓let MyLet = 0 ``` ```swift ↓let _myLet = 0 ``` ```swift private ↓let myLet_ = 0 ``` ```swift ↓let myExtremelyVeryVeryVeryVeryVeryVeryLongLet = 0 ``` ```swift ↓var myExtremelyVeryVeryVeryVeryVeryVeryLongVar = 0 ``` ```swift private ↓let _myExtremelyVeryVeryVeryVeryVeryVeryLongLet = 0 ``` ```swift ↓let i = 0 ``` ```swift ↓var id = 0 ``` ```swift private ↓let _i = 0 ``` ```swift ↓func IsOperator(name: String) -> Bool ``` ```swift enum Foo { case ↓MyEnum } ```
## Implicit Getter Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `implicit_getter` | Enabled | No | style | No | 3.0.0 Computed read-only properties and subscripts should avoid using the get keyword. ### Examples
Non Triggering Examples ```swift class Foo { var foo: Int { get { return 3 } set { _abc = newValue } } } ``` ```swift class Foo { var foo: Int { return 20 } } ``` ```swift class Foo { static var foo: Int { return 20 } } ``` ```swift class Foo { static var foo: Int { get { return 3 } set { _abc = newValue } } } ``` ```swift class Foo { var foo: Int } ``` ```swift class Foo { var foo: Int { return getValueFromDisk() } } ``` ```swift class Foo { var foo: String { return "get" } } ``` ```swift protocol Foo { var foo: Int { get } ``` ```swift protocol Foo { var foo: Int { get set } ``` ```swift class Foo { var foo: Int { struct Bar { var bar: Int { get { return 1 } set { _ = newValue } } } return Bar().bar } } ``` ```swift var _objCTaggedPointerBits: UInt { @inline(__always) get { return 0 } } ``` ```swift var next: Int? { mutating get { defer { self.count += 1 } return self.count } } ``` ```swift class Foo { subscript(i: Int) -> Int { return 20 } } ``` ```swift class Foo { subscript(i: Int) -> Int { get { return 3 } set { _abc = newValue } } } ``` ```swift protocol Foo { subscript(i: Int) -> Int { get } } ``` ```swift protocol Foo { subscript(i: Int) -> Int { get set } } ```
Triggering Examples ```swift class Foo { var foo: Int { ↓get { return 20 } } } ``` ```swift class Foo { var foo: Int { ↓get{ return 20 } } } ``` ```swift class Foo { static var foo: Int { ↓get { return 20 } } } ``` ```swift var foo: Int { ↓get { return 20 } } ``` ```swift class Foo { @objc func bar() {} var foo: Int { ↓get { return 20 } } } ``` ```swift class Foo { subscript(i: Int) -> Int { ↓get { return 20 } } } ```
## Implicit Return Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `implicit_return` | Disabled | Yes | style | No | 3.0.0 Prefer implicit returns in closures. ### Examples
Non Triggering Examples ```swift foo.map { $0 + 1 } ``` ```swift foo.map({ $0 + 1 }) ``` ```swift foo.map { value in value + 1 } ``` ```swift func foo() -> Int { return 0 } ``` ```swift if foo { return 0 } ``` ```swift var foo: Bool { return true } ```
Triggering Examples ```swift foo.map { value in ↓return value + 1 } ``` ```swift foo.map { ↓return $0 + 1 } ``` ```swift foo.map({ ↓return $0 + 1}) ``` ```swift [1, 2].first(where: { ↓return true }) ```
## Implicitly Unwrapped Optional Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `implicitly_unwrapped_optional` | Disabled | No | idiomatic | No | 3.0.0 Implicitly unwrapped optionals should be avoided when possible. ### Examples
Non Triggering Examples ```swift @IBOutlet private var label: UILabel! ``` ```swift @IBOutlet var label: UILabel! ``` ```swift @IBOutlet var label: [UILabel!] ``` ```swift if !boolean {} ``` ```swift let int: Int? = 42 ``` ```swift let int: Int? = nil ```
Triggering Examples ```swift let label: UILabel! ``` ```swift let IBOutlet: UILabel! ``` ```swift let labels: [UILabel!] ``` ```swift var ints: [Int!] = [42, nil, 42] ``` ```swift let label: IBOutlet! ``` ```swift let int: Int! = 42 ``` ```swift let int: Int! = nil ``` ```swift var int: Int! = 42 ``` ```swift let int: ImplicitlyUnwrappedOptional ``` ```swift let collection: AnyCollection ``` ```swift func foo(int: Int!) {} ```
## Inert Defer Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `inert_defer` | Enabled | No | lint | No | 3.0.0 If defer is at the end of its parent scope, it will be executed right where it is anyway. ### Examples
Non Triggering Examples ```swift func example3() { defer { /* deferred code */ } print("other code") } ``` ```swift func example4() { if condition { defer { /* deferred code */ } print("other code") } } ```
Triggering Examples ```swift func example0() { ↓defer { /* deferred code */ } } ``` ```swift func example1() { ↓defer { /* deferred code */ } // comment } ``` ```swift func example2() { if condition { ↓defer { /* deferred code */ } // comment } } ```
## Is Disjoint Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `is_disjoint` | Enabled | No | idiomatic | No | 3.0.0 Prefer using `Set.isDisjoint(with:)` over `Set.intersection(_:).isEmpty`. ### Examples
Non Triggering Examples ```swift _ = Set(syntaxKinds).isDisjoint(with: commentAndStringKindsSet) ``` ```swift let isObjc = !objcAttributes.isDisjoint(with: dictionary.enclosedSwiftAttributes) ``` ```swift _ = Set(syntaxKinds).intersection(commentAndStringKindsSet) ``` ```swift _ = !objcAttributes.intersection(dictionary.enclosedSwiftAttributes) ```
Triggering Examples ```swift _ = Set(syntaxKinds).↓intersection(commentAndStringKindsSet).isEmpty ``` ```swift let isObjc = !objcAttributes.↓intersection(dictionary.enclosedSwiftAttributes).isEmpty ```
## Joined Default Parameter Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `joined_default_parameter` | Disabled | Yes | idiomatic | No | 3.0.0 Discouraged explicit usage of the default separator. ### Examples
Non Triggering Examples ```swift let foo = bar.joined() ``` ```swift let foo = bar.joined(separator: ",") ``` ```swift let foo = bar.joined(separator: toto) ```
Triggering Examples ```swift let foo = bar.joined(↓separator: "") ``` ```swift let foo = bar.filter(toto) .joined(↓separator: "") ``` ```swift func foo() -> String { return ["1", "2"].joined(↓separator: "") } ```
## Large Tuple Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `large_tuple` | Enabled | No | metrics | No | 3.0.0 Tuples shouldn't have too many members. Create a custom type instead. ### Examples
Non Triggering Examples ```swift let foo: (Int, Int) ``` ```swift let foo: (start: Int, end: Int) ``` ```swift let foo: (Int, (Int, String)) ``` ```swift func foo() -> (Int, Int) ``` ```swift func foo() -> (Int, Int) {} ``` ```swift func foo(bar: String) -> (Int, Int) ``` ```swift func foo(bar: String) -> (Int, Int) {} ``` ```swift func foo() throws -> (Int, Int) ``` ```swift func foo() throws -> (Int, Int) {} ``` ```swift let foo: (Int, Int, Int) -> Void ``` ```swift let foo: (Int, Int, Int) throws -> Void ``` ```swift func foo(bar: (Int, String, Float) -> Void) ``` ```swift func foo(bar: (Int, String, Float) throws -> Void) ``` ```swift var completionHandler: ((_ data: Data?, _ resp: URLResponse?, _ e: NSError?) -> Void)! ``` ```swift func getDictionaryAndInt() -> (Dictionary, Int)? ``` ```swift func getGenericTypeAndInt() -> (Type, Int)? ```
Triggering Examples ```swift ↓let foo: (Int, Int, Int) ``` ```swift ↓let foo: (start: Int, end: Int, value: String) ``` ```swift ↓let foo: (Int, (Int, Int, Int)) ``` ```swift func foo(↓bar: (Int, Int, Int)) ``` ```swift func foo() -> ↓(Int, Int, Int) ``` ```swift func foo() -> ↓(Int, Int, Int) {} ``` ```swift func foo(bar: String) -> ↓(Int, Int, Int) ``` ```swift func foo(bar: String) -> ↓(Int, Int, Int) {} ``` ```swift func foo() throws -> ↓(Int, Int, Int) ``` ```swift func foo() throws -> ↓(Int, Int, Int) {} ``` ```swift func foo() throws -> ↓(Int, ↓(String, String, String), Int) {} ``` ```swift func getDictionaryAndInt() -> (Dictionary, Int)? ```
## Leading Whitespace Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `leading_whitespace` | Enabled | Yes | style | No | 3.0.0 Files should not contain leading whitespace. ### Examples
Non Triggering Examples ```swift // ```
Triggering Examples ```swift ``` ```swift // ```
## Legacy CGGeometry Functions Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `legacy_cggeometry_functions` | Enabled | Yes | idiomatic | No | 3.0.0 Struct extension properties and methods are preferred over legacy functions ### Examples
Non Triggering Examples ```swift rect.width ``` ```swift rect.height ``` ```swift rect.minX ``` ```swift rect.midX ``` ```swift rect.maxX ``` ```swift rect.minY ``` ```swift rect.midY ``` ```swift rect.maxY ``` ```swift rect.isNull ``` ```swift rect.isEmpty ``` ```swift rect.isInfinite ``` ```swift rect.standardized ``` ```swift rect.integral ``` ```swift rect.insetBy(dx: 5.0, dy: -7.0) ``` ```swift rect.offsetBy(dx: 5.0, dy: -7.0) ``` ```swift rect1.union(rect2) ``` ```swift rect1.intersect(rect2) ``` ```swift rect1.contains(rect2) ``` ```swift rect.contains(point) ``` ```swift rect1.intersects(rect2) ```
Triggering Examples ```swift ↓CGRectGetWidth(rect) ``` ```swift ↓CGRectGetHeight(rect) ``` ```swift ↓CGRectGetMinX(rect) ``` ```swift ↓CGRectGetMidX(rect) ``` ```swift ↓CGRectGetMaxX(rect) ``` ```swift ↓CGRectGetMinY(rect) ``` ```swift ↓CGRectGetMidY(rect) ``` ```swift ↓CGRectGetMaxY(rect) ``` ```swift ↓CGRectIsNull(rect) ``` ```swift ↓CGRectIsEmpty(rect) ``` ```swift ↓CGRectIsInfinite(rect) ``` ```swift ↓CGRectStandardize(rect) ``` ```swift ↓CGRectIntegral(rect) ``` ```swift ↓CGRectInset(rect, 10, 5) ``` ```swift ↓CGRectOffset(rect, -2, 8.3) ``` ```swift ↓CGRectUnion(rect1, rect2) ``` ```swift ↓CGRectIntersection(rect1, rect2) ``` ```swift ↓CGRectContainsRect(rect1, rect2) ``` ```swift ↓CGRectContainsPoint(rect, point) ``` ```swift ↓CGRectIntersectsRect(rect1, rect2) ```
## Legacy Constant Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `legacy_constant` | Enabled | Yes | idiomatic | No | 3.0.0 Struct-scoped constants are preferred over legacy global constants. ### Examples
Non Triggering Examples ```swift CGRect.infinite ``` ```swift CGPoint.zero ``` ```swift CGRect.zero ``` ```swift CGSize.zero ``` ```swift NSPoint.zero ``` ```swift NSRect.zero ``` ```swift NSSize.zero ``` ```swift CGRect.null ``` ```swift CGFloat.pi ``` ```swift Float.pi ```
Triggering Examples ```swift ↓CGRectInfinite ``` ```swift ↓CGPointZero ``` ```swift ↓CGRectZero ``` ```swift ↓CGSizeZero ``` ```swift ↓NSZeroPoint ``` ```swift ↓NSZeroRect ``` ```swift ↓NSZeroSize ``` ```swift ↓CGRectNull ``` ```swift ↓CGFloat(M_PI) ``` ```swift ↓Float(M_PI) ```
## Legacy Constructor Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `legacy_constructor` | Enabled | Yes | idiomatic | No | 3.0.0 Swift constructors are preferred over legacy convenience functions. ### Examples
Non Triggering Examples ```swift CGPoint(x: 10, y: 10) ``` ```swift CGPoint(x: xValue, y: yValue) ``` ```swift CGSize(width: 10, height: 10) ``` ```swift CGSize(width: aWidth, height: aHeight) ``` ```swift CGRect(x: 0, y: 0, width: 10, height: 10) ``` ```swift CGRect(x: xVal, y: yVal, width: aWidth, height: aHeight) ``` ```swift CGVector(dx: 10, dy: 10) ``` ```swift CGVector(dx: deltaX, dy: deltaY) ``` ```swift NSPoint(x: 10, y: 10) ``` ```swift NSPoint(x: xValue, y: yValue) ``` ```swift NSSize(width: 10, height: 10) ``` ```swift NSSize(width: aWidth, height: aHeight) ``` ```swift NSRect(x: 0, y: 0, width: 10, height: 10) ``` ```swift NSRect(x: xVal, y: yVal, width: aWidth, height: aHeight) ``` ```swift NSRange(location: 10, length: 1) ``` ```swift NSRange(location: loc, length: len) ``` ```swift UIEdgeInsets(top: 0, left: 0, bottom: 10, right: 10) ``` ```swift UIEdgeInsets(top: aTop, left: aLeft, bottom: aBottom, right: aRight) ``` ```swift NSEdgeInsets(top: 0, left: 0, bottom: 10, right: 10) ``` ```swift NSEdgeInsets(top: aTop, left: aLeft, bottom: aBottom, right: aRight) ``` ```swift UIOffset(horizontal: 0, vertical: 10) ``` ```swift UIOffset(horizontal: horizontal, vertical: vertical) ```
Triggering Examples ```swift ↓CGPointMake(10, 10) ``` ```swift ↓CGPointMake(xVal, yVal) ``` ```swift ↓CGPointMake(calculateX(), 10) ``` ```swift ↓CGSizeMake(10, 10) ``` ```swift ↓CGSizeMake(aWidth, aHeight) ``` ```swift ↓CGRectMake(0, 0, 10, 10) ``` ```swift ↓CGRectMake(xVal, yVal, width, height) ``` ```swift ↓CGVectorMake(10, 10) ``` ```swift ↓CGVectorMake(deltaX, deltaY) ``` ```swift ↓NSMakePoint(10, 10) ``` ```swift ↓NSMakePoint(xVal, yVal) ``` ```swift ↓NSMakeSize(10, 10) ``` ```swift ↓NSMakeSize(aWidth, aHeight) ``` ```swift ↓NSMakeRect(0, 0, 10, 10) ``` ```swift ↓NSMakeRect(xVal, yVal, width, height) ``` ```swift ↓NSMakeRange(10, 1) ``` ```swift ↓NSMakeRange(loc, len) ``` ```swift ↓UIEdgeInsetsMake(0, 0, 10, 10) ``` ```swift ↓UIEdgeInsetsMake(top, left, bottom, right) ``` ```swift ↓NSEdgeInsetsMake(0, 0, 10, 10) ``` ```swift ↓NSEdgeInsetsMake(top, left, bottom, right) ``` ```swift ↓CGVectorMake(10, 10) ↓NSMakeRange(10, 1) ``` ```swift ↓UIOffsetMake(0, 10) ``` ```swift ↓UIOffsetMake(horizontal, vertical) ```
## Legacy NSGeometry Functions Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `legacy_nsgeometry_functions` | Enabled | Yes | idiomatic | No | 3.0.0 Struct extension properties and methods are preferred over legacy functions ### Examples
Non Triggering Examples ```swift rect.width ``` ```swift rect.height ``` ```swift rect.minX ``` ```swift rect.midX ``` ```swift rect.maxX ``` ```swift rect.minY ``` ```swift rect.midY ``` ```swift rect.maxY ``` ```swift rect.isEmpty ``` ```swift rect.integral ``` ```swift rect.insetBy(dx: 5.0, dy: -7.0) ``` ```swift rect.offsetBy(dx: 5.0, dy: -7.0) ``` ```swift rect1.union(rect2) ``` ```swift rect1.intersect(rect2) ``` ```swift rect1.contains(rect2) ``` ```swift rect.contains(point) ``` ```swift rect1.intersects(rect2) ```
Triggering Examples ```swift ↓NSWidth(rect) ``` ```swift ↓NSHeight(rect) ``` ```swift ↓NSMinX(rect) ``` ```swift ↓NSMidX(rect) ``` ```swift ↓NSMaxX(rect) ``` ```swift ↓NSMinY(rect) ``` ```swift ↓NSMidY(rect) ``` ```swift ↓NSMaxY(rect) ``` ```swift ↓NSEqualRects(rect1, rect2) ``` ```swift ↓NSEqualSizes(size1, size2) ``` ```swift ↓NSEqualPoints(point1, point2) ``` ```swift ↓NSEdgeInsetsEqual(insets2, insets2) ``` ```swift ↓NSIsEmptyRect(rect) ``` ```swift ↓NSIntegralRect(rect) ``` ```swift ↓NSInsetRect(rect, 10, 5) ``` ```swift ↓NSOffsetRect(rect, -2, 8.3) ``` ```swift ↓NSUnionRect(rect1, rect2) ``` ```swift ↓NSIntersectionRect(rect1, rect2) ``` ```swift ↓NSContainsRect(rect1, rect2) ``` ```swift ↓NSPointInRect(rect, point) ``` ```swift ↓NSIntersectsRect(rect1, rect2) ```
## Variable Declaration Whitespace Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `let_var_whitespace` | Disabled | No | style | No | 3.0.0 Let and var should be separated from other statements by a blank line. ### Examples
Non Triggering Examples ```swift let a = 0 var x = 1 x = 2 ``` ```swift a = 5 var x = 1 ``` ```swift struct X { var a = 0 } ``` ```swift let a = 1 + 2 let b = 5 ``` ```swift var x: Int { return 0 } ``` ```swift var x: Int { let a = 0 return a } ``` ```swift #if os(macOS) let a = 0 #endif ``` ```swift @available(swift 4) let a = 0 ``` ```swift class C { @objc var s: String = "" } ``` ```swift class C { @objc func a() {} } ``` ```swift class C { var x = 0 lazy var y = 0 } ``` ```swift @available(OSX, introduced: 10.6) @available(*, deprecated) var x = 0 ``` ```swift // swiftlint:disable superfluous_disable_command // swiftlint:disable force_cast let x = bar as! Bar ``` ```swift var x: Int { let a = 0 return a } ```
Triggering Examples ```swift var x = 1 ↓x = 2 ``` ```swift a = 5 ↓var x = 1 ``` ```swift struct X { let a ↓func x() {} } ``` ```swift var x = 0 ↓@objc func f() {} ``` ```swift var x = 0 ↓@objc func f() {} ``` ```swift @objc func f() { } ↓var x = 0 ```
## Line Length Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `line_length` | Enabled | No | metrics | No | 3.0.0 Lines should not span too many characters. ### Examples
Non Triggering Examples ```swift //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ``` ```swift #colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1) ``` ```swift #imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg") ```
Triggering Examples ```swift ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ``` ```swift #colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)#colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1) ``` ```swift #imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg")#imageLiteral(resourceName: "image.jpg") ```
## Literal Expression End Indentation Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `literal_expression_end_indentation` | Disabled | Yes | style | No | 3.0.0 Array and dictionary literal end should have the same indentation as the line that started it. ### Examples
Non Triggering Examples ```swift [1, 2, 3] ``` ```swift [1, 2 ] ``` ```swift [ 1, 2 ] ``` ```swift [ 1, 2] ``` ```swift let x = [ 1, 2 ] ``` ```swift [key: 2, key2: 3] ``` ```swift [key: 1, key2: 2 ] ``` ```swift [ key: 0, key2: 20 ] ```
Triggering Examples ```swift let x = [ 1, 2 ↓] ``` ```swift let x = [ 1, 2 ↓] ``` ```swift let x = [ key: value ↓] ```
## Lower ACL than parent Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `lower_acl_than_parent` | Disabled | No | lint | No | 3.0.0 Ensure definitions have a lower access control level than their enclosing parent ### Examples
Non Triggering Examples ```swift public struct Foo { public func bar() {} } ``` ```swift internal struct Foo { func bar() {} } ``` ```swift struct Foo { func bar() {} } ``` ```swift open class Foo { public func bar() {} } ``` ```swift open class Foo { open func bar() {} } ``` ```swift fileprivate struct Foo { private func bar() {} } ``` ```swift private struct Foo { private func bar(id: String) } ``` ```swift extension Foo { public func bar() {} } ``` ```swift private struct Foo { fileprivate func bar() {} } ``` ```swift private func foo(id: String) {} ```
Triggering Examples ```swift struct Foo { public func bar() {} } ``` ```swift enum Foo { public func bar() {} } ``` ```swift public class Foo { open func bar() } ``` ```swift class Foo { public private(set) var bar: String? } ```
## Mark Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `mark` | Enabled | Yes | lint | No | 3.0.0 MARK comment should be in valid format. e.g. '// MARK: ...' or '// MARK: - ...' ### Examples
Non Triggering Examples ```swift // MARK: good ``` ```swift // MARK: - good ``` ```swift // MARK: - ``` ```swift // BOOKMARK ``` ```swift //BOOKMARK ``` ```swift // BOOKMARKS ```
Triggering Examples ```swift ↓//MARK: bad ``` ```swift ↓// MARK:bad ``` ```swift ↓//MARK:bad ``` ```swift ↓// MARK: bad ``` ```swift ↓// MARK: bad ``` ```swift ↓// MARK: -bad ``` ```swift ↓// MARK:- bad ``` ```swift ↓// MARK:-bad ``` ```swift ↓//MARK: - bad ``` ```swift ↓//MARK:- bad ``` ```swift ↓//MARK: -bad ``` ```swift ↓//MARK:-bad ``` ```swift ↓//Mark: bad ``` ```swift ↓// Mark: bad ``` ```swift ↓// MARK bad ``` ```swift ↓//MARK bad ``` ```swift ↓// MARK - bad ``` ```swift ↓//MARK : bad ``` ```swift ↓// MARKL: ``` ```swift ↓// MARKR ``` ```swift ↓// MARKK - ``` ```swift ↓//MARK:- Top-Level bad mark ↓//MARK:- Another bad mark struct MarkTest {} ↓// MARK:- Bad mark extension MarkTest {} ```
## Missing Docs Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `missing_docs` | Disabled | No | lint | No | 4.1.0 Declarations should be documented. ### Examples
Non Triggering Examples ```swift /// docs public class A { /// docs public func b() {} } /// docs public class B: A { override public func b() {} } ``` ```swift import Foundation /// docs public class B: NSObject { // no docs override public var description: String { fatalError() } } ```
Triggering Examples ```swift public func a() {} ``` ```swift // regular comment public func a() {} ``` ```swift /* regular comment */ public func a() {} ``` ```swift /// docs public protocol A { // no docs var b: Int { get } } /// docs public struct C: A { public let b: Int } ```
## Modifier Order Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `modifier_order` | Disabled | No | style | No | 4.1.0 Modifier order should be consistent. ### Examples
Non Triggering Examples ```swift public class Foo { public convenience required init() {} } ``` ```swift public class Foo { public static let bar = 42 } ``` ```swift public class Foo { public static var bar: Int { return 42 }} ``` ```swift public class Foo { public class var bar: Int { return 42 } } ``` ```swift public class Bar { public class var foo: String { return "foo" } } public class Foo: Bar { override public final class var foo: String { return "bar" } } ``` ```swift open class Bar { public var foo: Int? { return 42 } } open class Foo: Bar { override public var foo: Int? { return 43 } } ``` ```swift open class Bar { open class func foo() -> Int { return 42 } } class Foo: Bar { override open class func foo() -> Int { return 43 } } ``` ```swift protocol Foo: class {} class Bar { public private(set) weak var foo: Foo? } ``` ```swift @objc public final class Foo: NSObject {} ``` ```swift @objcMembers public final class Foo: NSObject {} ``` ```swift @objc override public private(set) weak var foo: Bar? ``` ```swift @objc public final class Foo: NSObject {} ``` ```swift @objc open final class Foo: NSObject { open weak var weakBar: NSString? = nil } ``` ```swift public final class Foo {} ``` ```swift class Bar { func bar() {} } ``` ```swift internal class Foo: Bar { override internal func bar() {} } ``` ```swift public struct Foo { internal weak var weakBar: NSObject? = nil } ``` ```swift class Foo { internal lazy var bar: String = "foo" } ```
Triggering Examples ```swift class Foo { convenience required public init() {} } ``` ```swift public class Foo { static public let bar = 42 } ``` ```swift public class Foo { static public var bar: Int { return 42 } } ``` ```swift public class Foo { class public var bar: Int { return 42 } } ``` ```swift public class RootFoo { class public var foo: String { return "foo" } } public class Foo: RootFoo { override final class public var foo: String { return "bar" } } ``` ```swift open class Bar { public var foo: Int? { return 42 } } open class Foo: Bar { public override var foo: Int? { return 43 } } ``` ```swift protocol Foo: class {} class Bar { private(set) public weak var foo: Foo? } ``` ```swift open class Bar { open class func foo() -> Int { return 42 } } class Foo: Bar { class open override func foo() -> Int { return 43 } } ``` ```swift open class Bar { open class func foo() -> Int { return 42 } } class Foo: Bar { open override class func foo() -> Int { return 43 } } ``` ```swift @objc final public class Foo: NSObject {} ``` ```swift @objcMembers final public class Foo: NSObject {} ``` ```swift @objc final open class Foo: NSObject { weak open var weakBar: NSString? = nil } ``` ```swift final public class Foo {} ``` ```swift internal class Foo: Bar { internal override func bar() {} } ``` ```swift public struct Foo { weak internal var weakBar: NSObjetc? = nil } ``` ```swift class Foo { lazy internal var bar: String = "foo" } ```
## Multiline Arguments Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `multiline_arguments` | Disabled | No | style | No | 3.0.0 Arguments should be either on the same line, or one per line. ### Examples
Non Triggering Examples ```swift foo() ``` ```swift foo( ) ``` ```swift foo { } ``` ```swift foo { } ``` ```swift foo(0) ``` ```swift foo(0, 1) ``` ```swift foo(0, 1) { } ``` ```swift foo(0, param1: 1) ``` ```swift foo(0, param1: 1) { } ``` ```swift foo(param1: 1) ``` ```swift foo(param1: 1) { } ``` ```swift foo(param1: 1, param2: true) { } ``` ```swift foo(param1: 1, param2: true, param3: [3]) { } ``` ```swift foo(param1: 1, param2: true, param3: [3]) { bar() } ``` ```swift foo(param1: 1, param2: true, param3: [3]) ``` ```swift foo( param1: 1, param2: true, param3: [3] ) ``` ```swift foo( param1: 1, param2: true, param3: [3] ) ```
Triggering Examples ```swift foo(0, param1: 1, ↓param2: true, ↓param3: [3]) ``` ```swift foo(0, ↓param1: 1, param2: true, ↓param3: [3]) ``` ```swift foo(0, ↓param1: 1, ↓param2: true, param3: [3]) ``` ```swift foo( 0, ↓param1: 1, param2: true, ↓param3: [3] ) ```
## Multiline Function Chains Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `multiline_function_chains` | Disabled | No | style | No | 3.0.0 Chained function calls should be either on the same line, or one per line. ### Examples
Non Triggering Examples ```swift let evenSquaresSum = [20, 17, 35, 4].filter { $0 % 2 == 0 }.map { $0 * $0 }.reduce(0, +) ``` ```swift let evenSquaresSum = [20, 17, 35, 4] .filter { $0 % 2 == 0 }.map { $0 * $0 }.reduce(0, +)", ``` ```swift let chain = a .b(1, 2, 3) .c { blah in print(blah) } .d() ``` ```swift let chain = a.b(1, 2, 3) .c { blah in print(blah) } .d() ``` ```swift let chain = a.b(1, 2, 3) .c { blah in print(blah) } .d() ``` ```swift let chain = a.b(1, 2, 3) .c(.init( a: 1, b, 2, c, 3)) .d() ``` ```swift self.viewModel.outputs.postContextualNotification .observeForUI() .observeValues { NotificationCenter.default.post( Notification( name: .ksr_showNotificationsDialog, userInfo: [UserInfoKeys.context: PushNotificationDialog.Context.pledge, UserInfoKeys.viewController: self] ) ) } ``` ```swift let remainingIDs = Array(Set(self.currentIDs).subtracting(Set(response.ids))) ``` ```swift self.happeningNewsletterOn = self.updateCurrentUser .map { $0.newsletters.happening }.skipNil().skipRepeats() ```
Triggering Examples ```swift let evenSquaresSum = [20, 17, 35, 4] .filter { $0 % 2 == 0 }↓.map { $0 * $0 } .reduce(0, +) ``` ```swift let evenSquaresSum = a.b(1, 2, 3) .c { blah in print(blah) }↓.d() ``` ```swift let evenSquaresSum = a.b(1, 2, 3) .c(2, 3, 4)↓.d() ``` ```swift let evenSquaresSum = a.b(1, 2, 3)↓.c { blah in print(blah) } .d() ``` ```swift a.b { // ““ }↓.e() ```
## Multiline Parameters Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `multiline_parameters` | Disabled | No | style | No | 3.0.0 Functions and methods parameters should be either on the same line, or one per line. ### Examples
Non Triggering Examples ```swift func foo() { } ``` ```swift func foo(param1: Int) { } ``` ```swift func foo(param1: Int, param2: Bool) { } ``` ```swift func foo(param1: Int, param2: Bool, param3: [String]) { } ``` ```swift func foo(param1: Int, param2: Bool, param3: [String]) { } ``` ```swift func foo(_ param1: Int, param2: Int, param3: Int) -> (Int) -> Int { return { x in x + param1 + param2 + param3 } } ``` ```swift static func foo() { } ``` ```swift static func foo(param1: Int) { } ``` ```swift static func foo(param1: Int, param2: Bool) { } ``` ```swift static func foo(param1: Int, param2: Bool, param3: [String]) { } ``` ```swift static func foo(param1: Int, param2: Bool, param3: [String]) { } ``` ```swift protocol Foo { func foo() { } } ``` ```swift protocol Foo { func foo(param1: Int) { } } ``` ```swift protocol Foo { func foo(param1: Int, param2: Bool) { } } ``` ```swift protocol Foo { func foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift protocol Foo { func foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift protocol Foo { static func foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift protocol Foo { static func foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift protocol Foo { class func foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift protocol Foo { class func foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift enum Foo { func foo() { } } ``` ```swift enum Foo { func foo(param1: Int) { } } ``` ```swift enum Foo { func foo(param1: Int, param2: Bool) { } } ``` ```swift enum Foo { func foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift enum Foo { func foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift enum Foo { static func foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift enum Foo { static func foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift struct Foo { func foo() { } } ``` ```swift struct Foo { func foo(param1: Int) { } } ``` ```swift struct Foo { func foo(param1: Int, param2: Bool) { } } ``` ```swift struct Foo { func foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift struct Foo { func foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift struct Foo { static func foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift struct Foo { static func foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift class Foo { func foo() { } } ``` ```swift class Foo { func foo(param1: Int) { } } ``` ```swift class Foo { func foo(param1: Int, param2: Bool) { } } ``` ```swift class Foo { func foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift class Foo { func foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift class Foo { class func foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift class Foo { class func foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift class Foo { class func foo(param1: Int, param2: Bool, param3: @escaping (Int, Int) -> Void = { _, _ in }) { } } ``` ```swift class Foo { class func foo(param1: Int, param2: Bool, param3: @escaping (Int) -> Void = { _ in }) { } } ``` ```swift class Foo { class func foo(param1: Int, param2: Bool, param3: @escaping ((Int) -> Void)? = nil) { } } ``` ```swift class Foo { class func foo(param1: Int, param2: Bool, param3: @escaping ((Int) -> Void)? = { _ in }) { } } ``` ```swift class Foo { class func foo(param1: Int, param2: @escaping ((Int) -> Void)? = { _ in }, param3: Bool) { } } ``` ```swift class Foo { class func foo(param1: Int, param2: @escaping ((Int) -> Void)? = { _ in }, param3: @escaping (Int, Int) -> Void = { _, _ in }) { } } ``` ```swift class Foo { class func foo(param1: Int, param2: Bool, param3: @escaping (Int) -> Void = { (x: Int) in }) { } } ``` ```swift class Foo { class func foo(param1: Int, param2: Bool, param3: @escaping (Int, (Int) -> Void) -> Void = { (x: Int, f: (Int) -> Void) in }) { } } ```
Triggering Examples ```swift func ↓foo(_ param1: Int, param2: Int, param3: Int) -> (Int) -> Int { return { x in x + param1 + param2 + param3 } } ``` ```swift protocol Foo { func ↓foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift protocol Foo { func ↓foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift protocol Foo { static func ↓foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift protocol Foo { static func ↓foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift protocol Foo { class func ↓foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift protocol Foo { class func ↓foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift enum Foo { func ↓foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift enum Foo { func ↓foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift enum Foo { static func ↓foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift enum Foo { static func ↓foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift struct Foo { func ↓foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift struct Foo { func ↓foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift struct Foo { static func ↓foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift struct Foo { static func ↓foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift class Foo { func ↓foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift class Foo { func ↓foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift class Foo { class func ↓foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift class Foo { class func ↓foo(param1: Int, param2: Bool, param3: [String]) { } } ``` ```swift class Foo { class func ↓foo(param1: Int, param2: Bool, param3: @escaping (Int, Int) -> Void = { _, _ in }) { } } ``` ```swift class Foo { class func ↓foo(param1: Int, param2: Bool, param3: @escaping (Int) -> Void = { (x: Int) in }) { } } ```
## Multiple Closures with Trailing Closure Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `multiple_closures_with_trailing_closure` | Enabled | No | style | No | 3.0.0 Trailing closure syntax should not be used when passing more than one closure argument. ### Examples
Non Triggering Examples ```swift foo.map { $0 + 1 } ``` ```swift foo.reduce(0) { $0 + $1 } ``` ```swift if let foo = bar.map({ $0 + 1 }) { } ``` ```swift foo.something(param1: { $0 }, param2: { $0 + 1 }) ``` ```swift UIView.animate(withDuration: 1.0) { someView.alpha = 0.0 } ```
Triggering Examples ```swift foo.something(param1: { $0 }) ↓{ $0 + 1 } ``` ```swift UIView.animate(withDuration: 1.0, animations: { someView.alpha = 0.0 }) ↓{ _ in someView.removeFromSuperview() } ```
## Nesting Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `nesting` | Enabled | No | metrics | No | 3.0.0 Types should be nested at most 1 level deep, and statements should be nested at most 5 levels deep. ### Examples
Non Triggering Examples ```swift class Class0 { class Class1 {} } ``` ```swift func func0() { func func1() { func func2() { func func3() { func func4() { func func5() { } } } } } } ``` ```swift struct Class0 { struct Class1 {} } ``` ```swift func func0() { func func1() { func func2() { func func3() { func func4() { func func5() { } } } } } } ``` ```swift enum Class0 { enum Class1 {} } ``` ```swift func func0() { func func1() { func func2() { func func3() { func func4() { func func5() { } } } } } } ``` ```swift enum Enum0 { enum Enum1 { case Case } } ```
Triggering Examples ```swift class A { class B { ↓class C {} } } ``` ```swift struct A { struct B { ↓struct C {} } } ``` ```swift enum A { enum B { ↓enum C {} } } ``` ```swift func func0() { func func1() { func func2() { func func3() { func func4() { func func5() { ↓func func6() { } } } } } } } ```
## Nimble Operator Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `nimble_operator` | Disabled | Yes | idiomatic | No | 3.0.0 Prefer Nimble operator overloads over free matcher functions. ### Examples
Non Triggering Examples ```swift expect(seagull.squawk) != "Hi!" ``` ```swift expect("Hi!") == "Hi!" ``` ```swift expect(10) > 2 ``` ```swift expect(10) >= 10 ``` ```swift expect(10) < 11 ``` ```swift expect(10) <= 10 ``` ```swift expect(x) === x ``` ```swift expect(10) == 10 ``` ```swift expect(object.asyncFunction()).toEventually(equal(1)) ``` ```swift expect(actual).to(haveCount(expected)) ```
Triggering Examples ```swift ↓expect(seagull.squawk).toNot(equal("Hi")) ``` ```swift ↓expect(12).toNot(equal(10)) ``` ```swift ↓expect(10).to(equal(10)) ``` ```swift ↓expect(10).to(beGreaterThan(8)) ``` ```swift ↓expect(10).to(beGreaterThanOrEqualTo(10)) ``` ```swift ↓expect(10).to(beLessThan(11)) ``` ```swift ↓expect(10).to(beLessThanOrEqualTo(10)) ``` ```swift ↓expect(x).to(beIdenticalTo(x)) ``` ```swift expect(10) > 2 ↓expect(10).to(beGreaterThan(2)) ```
## No Extension Access Modifier Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `no_extension_access_modifier` | Disabled | No | idiomatic | No | 3.0.0 Prefer not to use extension access modifiers ### Examples
Non Triggering Examples ```swift extension String {} ``` ```swift extension String {} ```
Triggering Examples ```swift ↓private extension String {} ``` ```swift ↓public extension String {} ``` ```swift ↓open extension String {} ``` ```swift ↓internal extension String {} ``` ```swift ↓fileprivate extension String {} ```
## No Fallthrough Only Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `no_fallthrough_only` | Enabled | No | idiomatic | No | 3.0.0 Fallthroughs can only be used if the `case` contains at least one other statement. ### Examples
Non Triggering Examples ```swift switch myvar { case 1: var a = 1 fallthrough case 2: var a = 2 } ``` ```swift switch myvar { case "a": var one = 1 var two = 2 fallthrough case "b": /* comment */ var three = 3 } ``` ```swift switch myvar { case 1: let one = 1 case 2: // comment var two = 2 } ``` ```swift switch myvar { case MyFunc(x: [1, 2, YourFunc(a: 23)], y: 2): var three = 3 fallthrough default: var three = 4 } ``` ```swift switch myvar { case .alpha: var one = 1 case .beta: var three = 3 fallthrough default: var four = 4 } ``` ```swift let aPoint = (1, -1) switch aPoint { case let (x, y) where x == y: let A = "A" case let (x, y) where x == -y: let B = "B" fallthrough default: let C = "C" } ``` ```swift switch myvar { case MyFun(with: { $1 }): let one = 1 fallthrough case "abc": let two = 2 } ```
Triggering Examples ```swift switch myvar { case 1: ↓fallthrough case 2: var a = 1 } ``` ```swift switch myvar { case 1: var a = 2 case 2: ↓fallthrough case 3: var a = 3 } ``` ```swift switch myvar { case 1: // comment ↓fallthrough } ``` ```swift switch myvar { case 1: /* multi line comment */ ↓fallthrough case 2: var a = 2 } ``` ```swift switch myvar { case MyFunc(x: [1, 2, YourFunc(a: 23)], y: 2): ↓fallthrough default: var three = 4 } ``` ```swift switch myvar { case .alpha: var one = 1 case .beta: ↓fallthrough case .gamma: var three = 3 default: var four = 4 } ``` ```swift let aPoint = (1, -1) switch aPoint { case let (x, y) where x == y: let A = "A" case let (x, y) where x == -y: ↓fallthrough default: let B = "B" } ``` ```swift switch myvar { case MyFun(with: { $1 }): ↓fallthrough case "abc": let two = 2 } ```
## No Grouping Extension Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `no_grouping_extension` | Disabled | No | idiomatic | No | 3.0.0 Extensions shouldn't be used to group code within the same source file. ### Examples
Non Triggering Examples ```swift protocol Food {} extension Food {} ``` ```swift class Apples {} extension Oranges {} ```
Triggering Examples ```swift enum Fruit {} ↓extension Fruit {} ``` ```swift ↓extension Tea: Error {} struct Tea {} ``` ```swift class Ham { class Spam {}} ↓extension Ham.Spam {} ``` ```swift extension External { struct Gotcha {}} ↓extension External.Gotcha {} ```
## Notification Center Detachment Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `notification_center_detachment` | Enabled | No | lint | No | 3.0.0 An object should only remove itself as an observer in `deinit`. ### Examples
Non Triggering Examples ```swift class Foo { deinit { NotificationCenter.default.removeObserver(self) } } ``` ```swift class Foo { func bar() { NotificationCenter.default.removeObserver(otherObject) } } ```
Triggering Examples ```swift class Foo { func bar() { ↓NotificationCenter.default.removeObserver(self) } } ```
## Number Separator Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `number_separator` | Disabled | Yes | style | No | 3.0.0 Underscores should be used as thousand separator in large decimal numbers. ### Examples
Non Triggering Examples ```swift let foo = -100 ``` ```swift let foo = -1_000 ``` ```swift let foo = -1_000_000 ``` ```swift let foo = -1.000_1 ``` ```swift let foo = -1_000_000.000_000_1 ``` ```swift let binary = -0b10000 ``` ```swift let binary = -0b1000_0001 ``` ```swift let hex = -0xA ``` ```swift let hex = -0xAA_BB ``` ```swift let octal = -0o21 ``` ```swift let octal = -0o21_1 ``` ```swift let exp = -1_000_000.000_000e2 ``` ```swift let foo = +100 ``` ```swift let foo = +1_000 ``` ```swift let foo = +1_000_000 ``` ```swift let foo = +1.000_1 ``` ```swift let foo = +1_000_000.000_000_1 ``` ```swift let binary = +0b10000 ``` ```swift let binary = +0b1000_0001 ``` ```swift let hex = +0xA ``` ```swift let hex = +0xAA_BB ``` ```swift let octal = +0o21 ``` ```swift let octal = +0o21_1 ``` ```swift let exp = +1_000_000.000_000e2 ``` ```swift let foo = 100 ``` ```swift let foo = 1_000 ``` ```swift let foo = 1_000_000 ``` ```swift let foo = 1.000_1 ``` ```swift let foo = 1_000_000.000_000_1 ``` ```swift let binary = 0b10000 ``` ```swift let binary = 0b1000_0001 ``` ```swift let hex = 0xA ``` ```swift let hex = 0xAA_BB ``` ```swift let octal = 0o21 ``` ```swift let octal = 0o21_1 ``` ```swift let exp = 1_000_000.000_000e2 ```
Triggering Examples ```swift let foo = ↓-10_0 ``` ```swift let foo = ↓-1000 ``` ```swift let foo = ↓-1000e2 ``` ```swift let foo = ↓-1000E2 ``` ```swift let foo = ↓-1__000 ``` ```swift let foo = ↓-1.0001 ``` ```swift let foo = ↓-1_000_000.000000_1 ``` ```swift let foo = ↓-1000000.000000_1 ``` ```swift let foo = +↓10_0 ``` ```swift let foo = +↓1000 ``` ```swift let foo = +↓1000e2 ``` ```swift let foo = +↓1000E2 ``` ```swift let foo = +↓1__000 ``` ```swift let foo = +↓1.0001 ``` ```swift let foo = +↓1_000_000.000000_1 ``` ```swift let foo = +↓1000000.000000_1 ``` ```swift let foo = ↓10_0 ``` ```swift let foo = ↓1000 ``` ```swift let foo = ↓1000e2 ``` ```swift let foo = ↓1000E2 ``` ```swift let foo = ↓1__000 ``` ```swift let foo = ↓1.0001 ``` ```swift let foo = ↓1_000_000.000000_1 ``` ```swift let foo = ↓1000000.000000_1 ```
## Object Literal Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `object_literal` | Disabled | No | idiomatic | No | 3.0.0 Prefer object literals over image and color inits. ### Examples
Non Triggering Examples ```swift let image = #imageLiteral(resourceName: "image.jpg") ``` ```swift let color = #colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1) ``` ```swift let image = UIImage(named: aVariable) ``` ```swift let image = UIImage(named: "interpolated \(variable)") ``` ```swift let color = UIColor(red: value, green: value, blue: value, alpha: 1) ``` ```swift let image = NSImage(named: aVariable) ``` ```swift let image = NSImage(named: "interpolated \(variable)") ``` ```swift let color = NSColor(red: value, green: value, blue: value, alpha: 1) ```
Triggering Examples ```swift let image = ↓UIImage(named: "foo") ``` ```swift let color = ↓UIColor(red: 0.3, green: 0.3, blue: 0.3, alpha: 1) ``` ```swift let color = ↓UIColor(red: 100 / 255.0, green: 50 / 255.0, blue: 0, alpha: 1) ``` ```swift let color = ↓UIColor(white: 0.5, alpha: 1) ``` ```swift let image = ↓NSImage(named: "foo") ``` ```swift let color = ↓NSColor(red: 0.3, green: 0.3, blue: 0.3, alpha: 1) ``` ```swift let color = ↓NSColor(red: 100 / 255.0, green: 50 / 255.0, blue: 0, alpha: 1) ``` ```swift let color = ↓NSColor(white: 0.5, alpha: 1) ``` ```swift let image = ↓UIImage.init(named: "foo") ``` ```swift let color = ↓UIColor.init(red: 0.3, green: 0.3, blue: 0.3, alpha: 1) ``` ```swift let color = ↓UIColor.init(red: 100 / 255.0, green: 50 / 255.0, blue: 0, alpha: 1) ``` ```swift let color = ↓UIColor.init(white: 0.5, alpha: 1) ``` ```swift let image = ↓NSImage.init(named: "foo") ``` ```swift let color = ↓NSColor.init(red: 0.3, green: 0.3, blue: 0.3, alpha: 1) ``` ```swift let color = ↓NSColor.init(red: 100 / 255.0, green: 50 / 255.0, blue: 0, alpha: 1) ``` ```swift let color = ↓NSColor.init(white: 0.5, alpha: 1) ```
## Opening Brace Spacing Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `opening_brace` | Enabled | Yes | style | No | 3.0.0 Opening braces should be preceded by a single space and on the same line as the declaration. ### Examples
Non Triggering Examples ```swift func abc() { } ``` ```swift [].map() { $0 } ``` ```swift [].map({ }) ``` ```swift if let a = b { } ``` ```swift while a == b { } ``` ```swift guard let a = b else { } ``` ```swift if let a = b, let c = d where a == c { } ``` ```swift while let a = b, let c = d where a == c { } ``` ```swift guard let a = b, let c = d where a == c else { } ``` ```swift struct Rule {} ``` ```swift struct Parent { struct Child { let foo: Int } } ```
Triggering Examples ```swift func abc()↓{ } ``` ```swift func abc() ↓{ } ``` ```swift [].map()↓{ $0 } ``` ```swift [].map( ↓{ } ) ``` ```swift if let a = b↓{ } ``` ```swift while a == b↓{ } ``` ```swift guard let a = b else↓{ } ``` ```swift if let a = b, let c = d where a == c↓{ } ``` ```swift while let a = b, let c = d where a == c↓{ } ``` ```swift guard let a = b, let c = d where a == c else↓{ } ``` ```swift struct Rule↓{} ``` ```swift struct Rule ↓{ } ``` ```swift struct Rule ↓{ } ``` ```swift struct Parent { struct Child ↓{ let foo: Int } } ```
## Operator Usage Whitespace Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `operator_usage_whitespace` | Disabled | Yes | style | No | 3.0.0 Operators should be surrounded by a single whitespace when they are being used. ### Examples
Non Triggering Examples ```swift let foo = 1 + 2 ``` ```swift let foo = 1 > 2 ``` ```swift let foo = !false ``` ```swift let foo: Int? ``` ```swift let foo: Array ``` ```swift let model = CustomView, NSAttributedString>() ``` ```swift let foo: [String] ``` ```swift let foo = 1 + 2 ``` ```swift let range = 1...3 ``` ```swift let range = 1 ... 3 ``` ```swift let range = 1..<3 ``` ```swift #if swift(>=3.0) foo() #endif ``` ```swift array.removeAtIndex(-200) ``` ```swift let name = "image-1" ``` ```swift button.setImage(#imageLiteral(resourceName: "image-1"), for: .normal) ``` ```swift let doubleValue = -9e-11 ``` ```swift let foo = GenericType<(UIViewController) -> Void>() ``` ```swift let foo = Foo, Baz>() ``` ```swift let foo = SignalProducer, Error>([ self.signal, next ]).flatten(.concat) ```
Triggering Examples ```swift let foo = 1↓+2 ``` ```swift let foo = 1↓ + 2 ``` ```swift let foo = 1↓ + 2 ``` ```swift let foo = 1↓ + 2 ``` ```swift let foo↓=1↓+2 ``` ```swift let foo↓=1 + 2 ``` ```swift let foo↓=bar ``` ```swift let range = 1↓ ..< 3 ``` ```swift let foo = bar↓ ?? 0 ``` ```swift let foo = bar↓??0 ``` ```swift let foo = bar↓ != 0 ``` ```swift let foo = bar↓ !== bar2 ``` ```swift let v8 = Int8(1)↓ << 6 ``` ```swift let v8 = 1↓ << (6) ``` ```swift let v8 = 1↓ << (6) let foo = 1 > 2 ```
## Operator Function Whitespace Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `operator_whitespace` | Enabled | No | style | No | 3.0.0 Operators should be surrounded by a single whitespace when defining them. ### Examples
Non Triggering Examples ```swift func <| (lhs: Int, rhs: Int) -> Int {} ``` ```swift func <|< (lhs: A, rhs: A) -> A {} ``` ```swift func abc(lhs: Int, rhs: Int) -> Int {} ```
Triggering Examples ```swift ↓func <|(lhs: Int, rhs: Int) -> Int {} ``` ```swift ↓func <|<(lhs: A, rhs: A) -> A {} ``` ```swift ↓func <| (lhs: Int, rhs: Int) -> Int {} ``` ```swift ↓func <|< (lhs: A, rhs: A) -> A {} ``` ```swift ↓func <| (lhs: Int, rhs: Int) -> Int {} ``` ```swift ↓func <|< (lhs: A, rhs: A) -> A {} ```
## Overridden methods call super Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `overridden_super_call` | Disabled | No | lint | No | 3.0.0 Some overridden methods should always call super ### Examples
Non Triggering Examples ```swift class VC: UIViewController { override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) } } ``` ```swift class VC: UIViewController { override func viewWillAppear(_ animated: Bool) { self.method1() super.viewWillAppear(animated) self.method2() } } ``` ```swift class VC: UIViewController { override func loadView() { } } ``` ```swift class Some { func viewWillAppear(_ animated: Bool) { } } ``` ```swift class VC: UIViewController { override func viewDidLoad() { defer { super.viewDidLoad() } } } ```
Triggering Examples ```swift class VC: UIViewController { override func viewWillAppear(_ animated: Bool) {↓ //Not calling to super self.method() } } ``` ```swift class VC: UIViewController { override func viewWillAppear(_ animated: Bool) {↓ super.viewWillAppear(animated) //Other code super.viewWillAppear(animated) } } ``` ```swift class VC: UIViewController { override func didReceiveMemoryWarning() {↓ } } ```
## Override in Extension Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `override_in_extension` | Disabled | No | lint | No | 3.0.0 Extensions shouldn't override declarations. ### Examples
Non Triggering Examples ```swift extension Person { var age: Int { return 42 } } ``` ```swift extension Person { func celebrateBirthday() {} } ``` ```swift class Employee: Person { override func celebrateBirthday() {} } ``` ```swift class Foo: NSObject {} extension Foo { override var description: String { return "" } } ``` ```swift struct Foo { class Bar: NSObject {} } extension Foo.Bar { override var description: String { return "" } } ```
Triggering Examples ```swift extension Person { override ↓var age: Int { return 42 } } ``` ```swift extension Person { override ↓func celebrateBirthday() {} } ```
## Pattern Matching Keywords Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `pattern_matching_keywords` | Disabled | No | idiomatic | No | 3.0.0 Combine multiple pattern matching bindings by moving keywords out of tuples. ### Examples
Non Triggering Examples ```swift switch foo { default: break } ``` ```swift switch foo { case 1: break } ``` ```swift switch foo { case bar: break } ``` ```swift switch foo { case let (x, y): break } ``` ```swift switch foo { case .foo(let x): break } ``` ```swift switch foo { case let .foo(x, y): break } ``` ```swift switch foo { case .foo(let x), .bar(let x): break } ``` ```swift switch foo { case .foo(let x, var y): break } ``` ```swift switch foo { case var (x, y): break } ``` ```swift switch foo { case .foo(var x): break } ``` ```swift switch foo { case var .foo(x, y): break } ```
Triggering Examples ```swift switch foo { case (↓let x, ↓let y): break } ``` ```swift switch foo { case .foo(↓let x, ↓let y): break } ``` ```swift switch foo { case (.yamlParsing(↓let x), .yamlParsing(↓let y)): break } ``` ```swift switch foo { case (↓var x, ↓var y): break } ``` ```swift switch foo { case .foo(↓var x, ↓var y): break } ``` ```swift switch foo { case (.yamlParsing(↓var x), .yamlParsing(↓var y)): break } ```
## Prefixed Top-Level Constant Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `prefixed_toplevel_constant` | Disabled | No | style | No | 3.0.0 Top-level constants should be prefixed by `k`. ### Examples
Non Triggering Examples ```swift private let kFoo = 20.0 ``` ```swift public let kFoo = false ``` ```swift internal let kFoo = "Foo" ``` ```swift let kFoo = true ``` ```swift struct Foo { let bar = 20.0 } ``` ```swift private var foo = 20.0 ``` ```swift public var foo = false ``` ```swift internal var foo = "Foo" ``` ```swift var foo = true ``` ```swift var foo = true, bar = true ``` ```swift var foo = true, let kFoo = true ``` ```swift let kFoo = true ``` ```swift var foo: Int { return a + b } ``` ```swift let kFoo = { return a + b }() ```
Triggering Examples ```swift private let ↓Foo = 20.0 ``` ```swift public let ↓Foo = false ``` ```swift internal let ↓Foo = "Foo" ``` ```swift let ↓Foo = true ``` ```swift let ↓foo = 2, ↓bar = true ``` ```swift var foo = true, let ↓Foo = true ``` ```swift let ↓foo = true ``` ```swift let ↓foo = { return a + b }() ```
## Private Actions Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `private_action` | Disabled | No | lint | No | 3.0.0 IBActions should be private. ### Examples
Non Triggering Examples ```swift class Foo { @IBAction private func barButtonTapped(_ sender: UIButton) {} } ``` ```swift struct Foo { @IBAction private func barButtonTapped(_ sender: UIButton) {} } ``` ```swift class Foo { @IBAction fileprivate func barButtonTapped(_ sender: UIButton) {} } ``` ```swift struct Foo { @IBAction fileprivate func barButtonTapped(_ sender: UIButton) {} } ``` ```swift private extension Foo { @IBAction func barButtonTapped(_ sender: UIButton) {} } ``` ```swift fileprivate extension Foo { @IBAction func barButtonTapped(_ sender: UIButton) {} } ```
Triggering Examples ```swift class Foo { @IBAction ↓func barButtonTapped(_ sender: UIButton) {} } ``` ```swift struct Foo { @IBAction ↓func barButtonTapped(_ sender: UIButton) {} } ``` ```swift class Foo { @IBAction public ↓func barButtonTapped(_ sender: UIButton) {} } ``` ```swift struct Foo { @IBAction public ↓func barButtonTapped(_ sender: UIButton) {} } ``` ```swift class Foo { @IBAction internal ↓func barButtonTapped(_ sender: UIButton) {} } ``` ```swift struct Foo { @IBAction internal ↓func barButtonTapped(_ sender: UIButton) {} } ``` ```swift extension Foo { @IBAction ↓func barButtonTapped(_ sender: UIButton) {} } ``` ```swift extension Foo { @IBAction public ↓func barButtonTapped(_ sender: UIButton) {} } ``` ```swift extension Foo { @IBAction internal ↓func barButtonTapped(_ sender: UIButton) {} } ``` ```swift public extension Foo { @IBAction ↓func barButtonTapped(_ sender: UIButton) {} } ``` ```swift internal extension Foo { @IBAction ↓func barButtonTapped(_ sender: UIButton) {} } ```
## Private Outlets Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `private_outlet` | Disabled | No | lint | No | 3.0.0 IBOutlets should be private to avoid leaking UIKit to higher layers. ### Examples
Non Triggering Examples ```swift class Foo { @IBOutlet private var label: UILabel? } ``` ```swift class Foo { @IBOutlet private var label: UILabel! } ``` ```swift class Foo { var notAnOutlet: UILabel } ``` ```swift class Foo { @IBOutlet weak private var label: UILabel? } ``` ```swift class Foo { @IBOutlet private weak var label: UILabel? } ```
Triggering Examples ```swift class Foo { @IBOutlet ↓var label: UILabel? } ``` ```swift class Foo { @IBOutlet ↓var label: UILabel! } ```
## Private over fileprivate Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `private_over_fileprivate` | Enabled | Yes | idiomatic | No | 3.0.0 Prefer `private` over `fileprivate` declarations. ### Examples
Non Triggering Examples ```swift extension String {} ``` ```swift private extension String {} ``` ```swift public enum MyEnum {} ``` ```swift open extension String {} ``` ```swift internal extension String {} ``` ```swift extension String { fileprivate func Something(){} } ``` ```swift class MyClass { fileprivate let myInt = 4 } ``` ```swift class MyClass { fileprivate(set) var myInt = 4 } ``` ```swift struct Outter { struct Inter { fileprivate struct Inner {} } } ```
Triggering Examples ```swift ↓fileprivate enum MyEnum {} ``` ```swift ↓fileprivate class MyClass { fileprivate(set) var myInt = 4 } ```
## Private Unit Test Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `private_unit_test` | Enabled | No | lint | No | 3.0.0 Unit tests marked private are silently skipped. ### Examples
Non Triggering Examples ```swift class FooTest: XCTestCase { func test1() {} internal func test2() {} public func test3() {} } ``` ```swift internal class FooTest: XCTestCase { func test1() {} internal func test2() {} public func test3() {} } ``` ```swift public class FooTest: XCTestCase { func test1() {} internal func test2() {} public func test3() {} } ``` ```swift private class Foo: NSObject { func test1() {} internal func test2() {} public func test3() {} } ``` ```swift private class Foo { func test1() {} internal func test2() {} public func test3() {} } ``` ```swift public class FooTest: XCTestCase { func test1(param: Int) {} } ```
Triggering Examples ```swift private ↓class FooTest: XCTestCase { func test1() {} internal func test2() {} public func test3() {} private func test4() {} } ``` ```swift class FooTest: XCTestCase { func test1() {} internal func test2() {} public func test3() {} private ↓func test4() {} } ``` ```swift internal class FooTest: XCTestCase { func test1() {} internal func test2() {} public func test3() {} private ↓func test4() {} } ``` ```swift public class FooTest: XCTestCase { func test1() {} internal func test2() {} public func test3() {} private ↓func test4() {} } ```
## Prohibited Interface Builder Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `prohibited_interface_builder` | Disabled | No | lint | No | 3.0.0 Creating views using Interface Builder should be avoided. ### Examples
Non Triggering Examples ```swift class ViewController: UIViewController { var label: UILabel! } ``` ```swift class ViewController: UIViewController { @objc func buttonTapped(_ sender: UIButton) {} } ```
Triggering Examples ```swift class ViewController: UIViewController { @IBOutlet ↓var label: UILabel! } ``` ```swift class ViewController: UIViewController { @IBAction ↓func buttonTapped(_ sender: UIButton) {} } ```
## Prohibited calls to super Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `prohibited_super_call` | Disabled | No | lint | No | 3.0.0 Some methods should not call super ### Examples
Non Triggering Examples ```swift class VC: UIViewController { override func loadView() { } } ``` ```swift class NSView { func updateLayer() { self.method1() } } ``` ```swift public class FileProviderExtension: NSFileProviderExtension { override func providePlaceholder(at url: URL, completionHandler: @escaping (Error?) -> Void) { guard let identifier = persistentIdentifierForItem(at: url) else { completionHandler(NSFileProviderError(.noSuchItem)) return } } } ```
Triggering Examples ```swift class VC: UIViewController { override func loadView() {↓ super.loadView() } } ``` ```swift class VC: NSFileProviderExtension { override func providePlaceholder(at url: URL, completionHandler: @escaping (Error?) -> Void) {↓ self.method1() super.providePlaceholder(at:url, completionHandler: completionHandler) } } ``` ```swift class VC: NSView { override func updateLayer() {↓ self.method1() super.updateLayer() self.method2() } } ``` ```swift class VC: NSView { override func updateLayer() {↓ defer { super.updateLayer() } } } ```
## Protocol Property Accessors Order Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `protocol_property_accessors_order` | Enabled | Yes | style | No | 3.0.0 When declaring properties in protocols, the order of accessors should be `get set`. ### Examples
Non Triggering Examples ```swift protocol Foo { var bar: String { get set } } ``` ```swift protocol Foo { var bar: String { get } } ``` ```swift protocol Foo { var bar: String { set } } ```
Triggering Examples ```swift protocol Foo { var bar: String { ↓set get } } ```
## Quick Discouraged Call Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `quick_discouraged_call` | Disabled | No | lint | No | 3.0.0 Discouraged call inside 'describe' and/or 'context' block. ### Examples
Non Triggering Examples ```swift class TotoTests: QuickSpec { override func spec() { describe("foo") { beforeEach { let foo = Foo() foo.toto() } } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { describe("foo") { beforeEach { let foo = Foo() foo.toto() } afterEach { let foo = Foo() foo.toto() } describe("bar") { } context("bar") { } it("bar") { let foo = Foo() foo.toto() } } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { describe("foo") { itBehavesLike("bar") } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { describe("foo") { it("does something") { let foo = Foo() foo.toto() } } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { context("foo") { afterEach { toto.append(foo) } } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { xcontext("foo") { afterEach { toto.append(foo) } } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { xdescribe("foo") { afterEach { toto.append(foo) } } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { describe("foo") { xit("does something") { let foo = Foo() foo.toto() } } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { fcontext("foo") { afterEach { toto.append(foo) } } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { fdescribe("foo") { afterEach { toto.append(foo) } } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { describe("foo") { fit("does something") { let foo = Foo() foo.toto() } } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { fitBehavesLike("foo") } } ``` ```swift class TotoTests: QuickSpec { override func spec() { xitBehavesLike("foo") } } ```
Triggering Examples ```swift class TotoTests { override func spec() { describe("foo") { let foo = Foo() } } } class TotoTests: QuickSpec { override func spec() { describe("foo") { let foo = ↓Foo() } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { describe("foo") { let foo = ↓Foo() } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { describe("foo") { context("foo") { let foo = ↓Foo() } context("bar") { let foo = ↓Foo() ↓foo.bar() it("does something") { let foo = Foo() foo.toto() } } } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { describe("foo") { context("foo") { context("foo") { beforeEach { let foo = Foo() foo.toto() } it("bar") { } context("foo") { let foo = ↓Foo() } } } } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { context("foo") { let foo = ↓Foo() } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { sharedExamples("foo") { let foo = ↓Foo() } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { describe("foo") { ↓foo() } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { context("foo") { ↓foo() } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { sharedExamples("foo") { ↓foo() } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { xdescribe("foo") { let foo = ↓Foo() } fdescribe("foo") { let foo = ↓Foo() } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { xcontext("foo") { let foo = ↓Foo() } fcontext("foo") { let foo = ↓Foo() } } } ```
## Quick Discouraged Focused Test Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `quick_discouraged_focused_test` | Disabled | No | lint | No | 3.0.0 Discouraged focused test. Other tests won't run while this one is focused. ### Examples
Non Triggering Examples ```swift class TotoTests: QuickSpec { override func spec() { describe("foo") { describe("bar") { } context("bar") { it("bar") { } } it("bar") { } itBehavesLike("bar") } } } ```
Triggering Examples ```swift class TotoTests: QuickSpec { override func spec() { ↓fdescribe("foo") { } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { ↓fcontext("foo") { } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { ↓fit("foo") { } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { describe("foo") { ↓fit("bar") { } } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { context("foo") { ↓fit("bar") { } } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { describe("foo") { context("bar") { ↓fit("toto") { } } } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { ↓fitBehavesLike("foo") } } ```
## Quick Discouraged Pending Test Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `quick_discouraged_pending_test` | Disabled | No | lint | No | 3.0.0 Discouraged pending test. This test won't run while it's marked as pending. ### Examples
Non Triggering Examples ```swift class TotoTests: QuickSpec { override func spec() { describe("foo") { describe("bar") { } context("bar") { it("bar") { } } it("bar") { } itBehavesLike("bar") } } } ```
Triggering Examples ```swift class TotoTests: QuickSpec { override func spec() { ↓xdescribe("foo") { } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { ↓xcontext("foo") { } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { ↓xit("foo") { } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { describe("foo") { ↓xit("bar") { } } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { context("foo") { ↓xit("bar") { } } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { describe("foo") { context("bar") { ↓xit("toto") { } } } } } ``` ```swift class TotoTests: QuickSpec { override func spec() { ↓pending("foo") } } ``` ```swift class TotoTests: QuickSpec { override func spec() { ↓xitBehavesLike("foo") } } ```
## Redundant Discardable Let Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `redundant_discardable_let` | Enabled | Yes | style | No | 3.0.0 Prefer `_ = foo()` over `let _ = foo()` when discarding a result from a function. ### Examples
Non Triggering Examples ```swift _ = foo() ``` ```swift if let _ = foo() { } ``` ```swift guard let _ = foo() else { return } ``` ```swift let _: ExplicitType = foo() ``` ```swift while let _ = SplashStyle(rawValue: maxValue) { maxValue += 1 } ```
Triggering Examples ```swift ↓let _ = foo() ``` ```swift if _ = foo() { ↓let _ = bar() } ```
## Redundant Nil Coalescing Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `redundant_nil_coalescing` | Disabled | Yes | idiomatic | No | 3.0.0 nil coalescing operator is only evaluated if the lhs is nil, coalescing operator with nil as rhs is redundant ### Examples
Non Triggering Examples ```swift var myVar: Int?; myVar ?? 0 ```
Triggering Examples ```swift var myVar: Int? = nil; myVar↓ ?? nil ``` ```swift var myVar: Int? = nil; myVar↓??nil ```
## Redundant Optional Initialization Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `redundant_optional_initialization` | Enabled | Yes | idiomatic | No | 3.0.0 Initializing an optional variable with nil is redundant. ### Examples
Non Triggering Examples ```swift var myVar: Int? ``` ```swift let myVar: Int? = nil ``` ```swift var myVar: Int? = 0 ``` ```swift func foo(bar: Int? = 0) { } ``` ```swift var myVar: Optional ``` ```swift let myVar: Optional = nil ``` ```swift var myVar: Optional = 0 ``` ```swift var foo: Int? { if bar != nil { } return 0 } ``` ```swift var foo: Int? = { if bar != nil { } return 0 }() ``` ```swift lazy var test: Int? = nil ``` ```swift func funcName() { var myVar: String? } ``` ```swift func funcName() { let myVar: String? = nil } ```
Triggering Examples ```swift var myVar: Int?↓ = nil ``` ```swift var myVar: Optional↓ = nil ``` ```swift var myVar: Int?↓=nil ``` ```swift var myVar: Optional↓=nil ``` ```swift func funcName() { var myVar: String?↓ = nil } ```
## Redundant Set Access Control Rule Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `redundant_set_access_control` | Enabled | No | idiomatic | No | 4.1.0 Property setter access level shouldn't be explicit if it's the same as the variable access level. ### Examples
Non Triggering Examples ```swift private(set) public var foo: Int ``` ```swift public let foo: Int ``` ```swift public var foo: Int ``` ```swift var foo: Int ``` ```swift private final class A { private(set) var value: Int } ```
Triggering Examples ```swift ↓private(set) private var foo: Int ``` ```swift ↓fileprivate(set) fileprivate var foo: Int ``` ```swift ↓internal(set) internal var foo: Int ``` ```swift ↓public(set) public var foo: Int ``` ```swift open class Foo { ↓open(set) open var bar: Int } ``` ```swift class A { ↓internal(set) var value: Int } ``` ```swift fileprivate class A { ↓fileprivate(set) var value: Int } ```
## Redundant String Enum Value Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `redundant_string_enum_value` | Enabled | No | idiomatic | No | 3.0.0 String enum values can be omitted when they are equal to the enumcase name. ### Examples
Non Triggering Examples ```swift enum Numbers: String { case one case two } ``` ```swift enum Numbers: Int { case one = 1 case two = 2 } ``` ```swift enum Numbers: String { case one = "ONE" case two = "TWO" } ``` ```swift enum Numbers: String { case one = "ONE" case two = "two" } ``` ```swift enum Numbers: String { case one, two } ```
Triggering Examples ```swift enum Numbers: String { case one = ↓"one" case two = ↓"two" } ``` ```swift enum Numbers: String { case one = ↓"one", two = ↓"two" } ``` ```swift enum Numbers: String { case one, two = ↓"two" } ```
## Redundant Type Annotation Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `redundant_type_annotation` | Disabled | Yes | idiomatic | No | 3.0.0 Variables should not have redundant type annotation ### Examples
Non Triggering Examples ```swift var url = URL() ``` ```swift var url: CustomStringConvertible = URL() ```
Triggering Examples ```swift var url↓:URL=URL() ``` ```swift var url↓:URL = URL(string: "") ``` ```swift var url↓: URL = URL() ``` ```swift let url↓: URL = URL() ``` ```swift lazy var url↓: URL = URL() ``` ```swift let alphanumerics↓: CharacterSet = CharacterSet.alphanumerics ``` ```swift class ViewController: UIViewController { func someMethod() { let myVar↓: Int = Int(5) } } ```
## Redundant Void Return Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `redundant_void_return` | Enabled | Yes | idiomatic | No | 3.0.0 Returning Void in a function declaration is redundant. ### Examples
Non Triggering Examples ```swift func foo() {} ``` ```swift func foo() -> Int {} ``` ```swift func foo() -> Int -> Void {} ``` ```swift func foo() -> VoidResponse ``` ```swift let foo: Int -> Void ``` ```swift func foo() -> Int -> () {} ``` ```swift let foo: Int -> () ``` ```swift func foo() -> ()? ``` ```swift func foo() -> ()! ``` ```swift func foo() -> Void? ``` ```swift func foo() -> Void! ```
Triggering Examples ```swift func foo()↓ -> Void {} ``` ```swift protocol Foo { func foo()↓ -> Void } ``` ```swift func foo()↓ -> () {} ``` ```swift protocol Foo { func foo()↓ -> () } ```
## Required Enum Case Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `required_enum_case` | Disabled | No | lint | No | 3.0.0 Enums conforming to a specified protocol must implement a specific case(s). ### Examples
Non Triggering Examples ```swift enum MyNetworkResponse: String, NetworkResponsable { case success, error, notConnected } ``` ```swift enum MyNetworkResponse: String, NetworkResponsable { case success, error, notConnected(error: Error) } ``` ```swift enum MyNetworkResponse: String, NetworkResponsable { case success case error case notConnected } ``` ```swift enum MyNetworkResponse: String, NetworkResponsable { case success case error case notConnected(error: Error) } ```
Triggering Examples ```swift enum MyNetworkResponse: String, NetworkResponsable { case success, error } ``` ```swift enum MyNetworkResponse: String, NetworkResponsable { case success, error } ``` ```swift enum MyNetworkResponse: String, NetworkResponsable { case success case error } ``` ```swift enum MyNetworkResponse: String, NetworkResponsable { case success case error } ```
## Returning Whitespace Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `return_arrow_whitespace` | Enabled | Yes | style | No | 3.0.0 Return arrow and return type should be separated by a single space or on a separate line. ### Examples
Non Triggering Examples ```swift func abc() -> Int {} ``` ```swift func abc() -> [Int] {} ``` ```swift func abc() -> (Int, Int) {} ``` ```swift var abc = {(param: Int) -> Void in } ``` ```swift func abc() -> Int {} ``` ```swift func abc() -> Int {} ```
Triggering Examples ```swift func abc()↓->Int {} ``` ```swift func abc()↓->[Int] {} ``` ```swift func abc()↓->(Int, Int) {} ``` ```swift func abc()↓-> Int {} ``` ```swift func abc()↓ ->Int {} ``` ```swift func abc()↓ -> Int {} ``` ```swift var abc = {(param: Int)↓ ->Bool in } ``` ```swift var abc = {(param: Int)↓->Bool in } ```
## Shorthand Operator Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `shorthand_operator` | Enabled | No | style | No | 3.0.0 Prefer shorthand operators (+=, -=, *=, /=) over doing the operation and assigning. ### Examples
Non Triggering Examples ```swift foo -= 1 ``` ```swift foo -= variable ``` ```swift foo -= bar.method() ``` ```swift self.foo = foo - 1 ``` ```swift foo = self.foo - 1 ``` ```swift page = ceilf(currentOffset - pageWidth) ``` ```swift foo = aMethod(foo - bar) ``` ```swift foo = aMethod(bar - foo) ``` ```swift foo /= 1 ``` ```swift foo /= variable ``` ```swift foo /= bar.method() ``` ```swift self.foo = foo / 1 ``` ```swift foo = self.foo / 1 ``` ```swift page = ceilf(currentOffset / pageWidth) ``` ```swift foo = aMethod(foo / bar) ``` ```swift foo = aMethod(bar / foo) ``` ```swift foo += 1 ``` ```swift foo += variable ``` ```swift foo += bar.method() ``` ```swift self.foo = foo + 1 ``` ```swift foo = self.foo + 1 ``` ```swift page = ceilf(currentOffset + pageWidth) ``` ```swift foo = aMethod(foo + bar) ``` ```swift foo = aMethod(bar + foo) ``` ```swift foo *= 1 ``` ```swift foo *= variable ``` ```swift foo *= bar.method() ``` ```swift self.foo = foo * 1 ``` ```swift foo = self.foo * 1 ``` ```swift page = ceilf(currentOffset * pageWidth) ``` ```swift foo = aMethod(foo * bar) ``` ```swift foo = aMethod(bar * foo) ``` ```swift var helloWorld = "world!" helloWorld = "Hello, " + helloWorld ``` ```swift angle = someCheck ? angle : -angle ``` ```swift seconds = seconds * 60 + value ```
Triggering Examples ```swift ↓foo = foo - 1 ``` ```swift ↓foo = foo - aVariable ``` ```swift ↓foo = foo - bar.method() ``` ```swift ↓foo.aProperty = foo.aProperty - 1 ``` ```swift ↓self.aProperty = self.aProperty - 1 ``` ```swift ↓foo = foo / 1 ``` ```swift ↓foo = foo / aVariable ``` ```swift ↓foo = foo / bar.method() ``` ```swift ↓foo.aProperty = foo.aProperty / 1 ``` ```swift ↓self.aProperty = self.aProperty / 1 ``` ```swift ↓foo = foo + 1 ``` ```swift ↓foo = foo + aVariable ``` ```swift ↓foo = foo + bar.method() ``` ```swift ↓foo.aProperty = foo.aProperty + 1 ``` ```swift ↓self.aProperty = self.aProperty + 1 ``` ```swift ↓foo = foo * 1 ``` ```swift ↓foo = foo * aVariable ``` ```swift ↓foo = foo * bar.method() ``` ```swift ↓foo.aProperty = foo.aProperty * 1 ``` ```swift ↓self.aProperty = self.aProperty * 1 ``` ```swift n = n + i / outputLength ``` ```swift n = n - i / outputLength ```
## Single Test Class Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `single_test_class` | Disabled | No | style | No | 3.0.0 Test files should contain a single QuickSpec or XCTestCase class. ### Examples
Non Triggering Examples ```swift class FooTests { } ``` ```swift class FooTests: QuickSpec { } ``` ```swift class FooTests: XCTestCase { } ```
Triggering Examples ```swift ↓class FooTests: QuickSpec { } ↓class BarTests: QuickSpec { } ``` ```swift ↓class FooTests: QuickSpec { } ↓class BarTests: QuickSpec { } ↓class TotoTests: QuickSpec { } ``` ```swift ↓class FooTests: XCTestCase { } ↓class BarTests: XCTestCase { } ``` ```swift ↓class FooTests: XCTestCase { } ↓class BarTests: XCTestCase { } ↓class TotoTests: XCTestCase { } ``` ```swift ↓class FooTests: QuickSpec { } ↓class BarTests: XCTestCase { } ``` ```swift ↓class FooTests: QuickSpec { } ↓class BarTests: XCTestCase { } class TotoTests { } ```
## Min or Max over Sorted First or Last Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `sorted_first_last` | Disabled | No | performance | No | 3.0.0 Prefer using `min()` or `max()` over `sorted().first` or `sorted().last` ### Examples
Non Triggering Examples ```swift let min = myList.min() ``` ```swift let min = myList.min(by: { $0 < $1 }) ``` ```swift let min = myList.min(by: >) ``` ```swift let min = myList.max() ``` ```swift let min = myList.max(by: { $0 < $1 }) ```
Triggering Examples ```swift ↓myList.sorted().first ``` ```swift ↓myList.sorted(by: { $0.description < $1.description }).first ``` ```swift ↓myList.sorted(by: >).first ``` ```swift ↓myList.map { $0 + 1 }.sorted().first ``` ```swift ↓myList.sorted(by: someFunction).first ``` ```swift ↓myList.map { $0 + 1 }.sorted { $0.description < $1.description }.first ``` ```swift ↓myList.sorted().last ``` ```swift ↓myList.sorted().last?.something() ``` ```swift ↓myList.sorted(by: { $0.description < $1.description }).last ``` ```swift ↓myList.map { $0 + 1 }.sorted().last ``` ```swift ↓myList.sorted(by: someFunction).last ``` ```swift ↓myList.map { $0 + 1 }.sorted { $0.description < $1.description }.last ``` ```swift ↓myList.map { $0 + 1 }.sorted { $0.first < $1.first }.last ```
## Sorted Imports Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `sorted_imports` | Disabled | Yes | style | No | 3.0.0 Imports should be sorted. ### Examples
Non Triggering Examples ```swift import AAA import BBB import CCC import DDD ``` ```swift import Alamofire import API ``` ```swift import labc import Ldef ``` ```swift import BBB // comment import AAA import CCC ``` ```swift @testable import AAA import CCC ``` ```swift import AAA @testable import CCC ``` ```swift import EEE.A import FFF.B #if os(Linux) import DDD.A import EEE.B #else import CCC import DDD.B #endif import AAA import BBB ```
Triggering Examples ```swift import AAA import ZZZ import ↓BBB import CCC ``` ```swift import DDD // comment import CCC import ↓AAA ``` ```swift @testable import CCC import ↓AAA ``` ```swift import CCC @testable import ↓AAA ``` ```swift import FFF.B import ↓EEE.A #if os(Linux) import DDD.A import EEE.B #else import DDD.B import ↓CCC #endif import AAA import BBB ```
## Statement Position Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `statement_position` | Enabled | Yes | style | No | 3.0.0 Else and catch should be on the same line, one space after the previous declaration. ### Examples
Non Triggering Examples ```swift } else if { ``` ```swift } else { ``` ```swift } catch { ``` ```swift "}else{" ``` ```swift struct A { let catchphrase: Int } let a = A( catchphrase: 0 ) ``` ```swift struct A { let `catch`: Int } let a = A( `catch`: 0 ) ```
Triggering Examples ```swift ↓}else if { ``` ```swift ↓} else { ``` ```swift ↓} catch { ``` ```swift ↓} catch { ```
## Strict fileprivate Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `strict_fileprivate` | Disabled | No | idiomatic | No | 3.0.0 `fileprivate` should be avoided. ### Examples
Non Triggering Examples ```swift extension String {} ``` ```swift private extension String {} ``` ```swift public extension String {} ``` ```swift open extension String {} ``` ```swift internal extension String {} ```
Triggering Examples ```swift ↓fileprivate extension String {} ``` ```swift ↓fileprivate extension String {} ``` ```swift ↓fileprivate extension String {} ``` ```swift extension String { ↓fileprivate func Something(){} } ``` ```swift class MyClass { ↓fileprivate let myInt = 4 } ``` ```swift class MyClass { ↓fileprivate(set) var myInt = 4 } ``` ```swift struct Outter { struct Inter { ↓fileprivate struct Inner {} } } ```
## Superfluous Disable Command Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `superfluous_disable_command` | Enabled | No | lint | No | 3.0.0 SwiftLint 'disable' commands are superfluous when the disabled rule would not have triggered a violation in the disabled region. ## Switch and Case Statement Alignment Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `switch_case_alignment` | Enabled | No | style | No | 3.0.0 Case statements should vertically align with their enclosing switch statement, or indented if configured otherwise. ### Examples
Non Triggering Examples ```swift switch someBool { case true: // case 1 print('red') case false: /* case 2 */ if case let .someEnum(val) = someFunc() { print('blue') } } enum SomeEnum { case innocent } ``` ```swift if aBool { switch someBool { case true: print('red') case false: print('blue') } } ``` ```swift switch someInt { // comments ignored case 0: // zero case print('Zero') case 1: print('One') default: print('Some other number') } ```
Triggering Examples ```swift switch someBool { ↓case true: print("red") ↓case false: print("blue") } ``` ```swift if aBool { switch someBool { ↓case true: print('red') ↓case false: print('blue') } } ``` ```swift switch someInt { ↓case 0: print('Zero') ↓case 1: print('One') ↓default: print('Some other number') } ``` ```swift switch someBool { case true: print('red') ↓case false: print('blue') } ``` ```swift if aBool { switch someBool { ↓case true: print('red') case false: print('blue') } } ```
## Switch Case on Newline Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `switch_case_on_newline` | Disabled | No | style | No | 3.0.0 Cases inside a switch should always be on a newline ### Examples
Non Triggering Examples ```swift /*case 1: */return true ``` ```swift //case 1: return true ``` ```swift let x = [caseKey: value] ``` ```swift let x = [key: .default] ``` ```swift if case let .someEnum(value) = aFunction([key: 2]) { } ``` ```swift guard case let .someEnum(value) = aFunction([key: 2]) { } ``` ```swift for case let .someEnum(value) = aFunction([key: 2]) { } ``` ```swift enum Environment { case development } ``` ```swift enum Environment { case development(url: URL) } ``` ```swift enum Environment { case development(url: URL) // staging } ``` ```swift switch foo { case 1: return true } ``` ```swift switch foo { default: return true } ``` ```swift switch foo { case let value: return true } ``` ```swift switch foo { case .myCase: // error from network return true } ``` ```swift switch foo { case let .myCase(value) where value > 10: return false } ``` ```swift switch foo { case let .myCase(value) where value > 10: return false } ``` ```swift switch foo { case let .myCase(code: lhsErrorCode, description: _) where lhsErrorCode > 10: return false } ``` ```swift switch foo { case #selector(aFunction(_:)): return false } ```
Triggering Examples ```swift switch foo { ↓case 1: return true } ``` ```swift switch foo { ↓case let value: return true } ``` ```swift switch foo { ↓default: return true } ``` ```swift switch foo { ↓case "a string": return false } ``` ```swift switch foo { ↓case .myCase: return false // error from network } ``` ```swift switch foo { ↓case let .myCase(value) where value > 10: return false } ``` ```swift switch foo { ↓case #selector(aFunction(_:)): return false } ``` ```swift switch foo { ↓case let .myCase(value) where value > 10: return false } ``` ```swift switch foo { ↓case .first, .second: return false } ```
## Syntactic Sugar Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `syntactic_sugar` | Enabled | No | idiomatic | No | 3.0.0 Shorthand syntactic sugar should be used, i.e. [Int] instead of Array. ### Examples
Non Triggering Examples ```swift let x: [Int] ``` ```swift let x: [Int: String] ``` ```swift let x: Int? ``` ```swift func x(a: [Int], b: Int) -> [Int: Any] ``` ```swift let x: Int! ``` ```swift extension Array { func x() { } } ``` ```swift extension Dictionary { func x() { } } ``` ```swift let x: CustomArray ``` ```swift var currentIndex: Array.Index? ``` ```swift func x(a: [Int], b: Int) -> Array.Index ``` ```swift unsafeBitCast(nonOptionalT, to: Optional.self) ``` ```swift type is Optional.Type ``` ```swift let x: Foo.Optional ```
Triggering Examples ```swift let x: ↓Array ``` ```swift let x: ↓Dictionary ``` ```swift let x: ↓Optional ``` ```swift let x: ↓ImplicitlyUnwrappedOptional ``` ```swift func x(a: ↓Array, b: Int) -> [Int: Any] ``` ```swift func x(a: [Int], b: Int) -> ↓Dictionary ``` ```swift func x(a: ↓Array, b: Int) -> ↓Dictionary ``` ```swift let x = ↓Array.array(of: object) ``` ```swift let x: ↓Swift.Optional ```
## Todo Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `todo` | Enabled | No | lint | No | 3.0.0 TODOs and FIXMEs should be resolved. ### Examples
Non Triggering Examples ```swift // notaTODO: ``` ```swift // notaFIXME: ```
Triggering Examples ```swift // ↓TODO: ``` ```swift // ↓FIXME: ``` ```swift // ↓TODO(note) ``` ```swift // ↓FIXME(note) ``` ```swift /* ↓FIXME: */ ``` ```swift /* ↓TODO: */ ``` ```swift /** ↓FIXME: */ ``` ```swift /** ↓TODO: */ ```
## Toggle Bool Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `toggle_bool` | Disabled | No | idiomatic | No | 4.2.0 Prefer `someBool.toggle()` over `someBool = !someBool`. ### Examples
Non Triggering Examples ```swift isHidden.toggle() ``` ```swift view.clipsToBounds.toggle() ``` ```swift func foo() { abc.toggle() } ```
Triggering Examples ```swift ↓isHidden = !isHidden ``` ```swift ↓view.clipsToBounds = !view.clipsToBounds ``` ```swift func foo() { ↓abc = !abc } ```
## Trailing Closure Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `trailing_closure` | Disabled | No | style | No | 3.0.0 Trailing closure syntax should be used whenever possible. ### Examples
Non Triggering Examples ```swift foo.map { $0 + 1 } ``` ```swift foo.bar() ``` ```swift foo.reduce(0) { $0 + 1 } ``` ```swift if let foo = bar.map({ $0 + 1 }) { } ``` ```swift foo.something(param1: { $0 }, param2: { $0 + 1 }) ``` ```swift offsets.sorted { $0.offset < $1.offset } ```
Triggering Examples ```swift ↓foo.map({ $0 + 1 }) ``` ```swift ↓foo.reduce(0, combine: { $0 + 1 }) ``` ```swift ↓offsets.sorted(by: { $0.offset < $1.offset }) ``` ```swift ↓foo.something(0, { $0 + 1 }) ```
## Trailing Comma Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `trailing_comma` | Enabled | Yes | style | No | 3.0.0 Trailing commas in arrays and dictionaries should be avoided/enforced. ### Examples
Non Triggering Examples ```swift let foo = [1, 2, 3] ``` ```swift let foo = [] ``` ```swift let foo = [:] ``` ```swift let foo = [1: 2, 2: 3] ``` ```swift let foo = [Void]() ``` ```swift let example = [ 1, 2 // 3, ] ``` ```swift foo([1: "\(error)"]) ```
Triggering Examples ```swift let foo = [1, 2, 3↓,] ``` ```swift let foo = [1, 2, 3↓, ] ``` ```swift let foo = [1, 2, 3 ↓,] ``` ```swift let foo = [1: 2, 2: 3↓, ] ``` ```swift struct Bar { let foo = [1: 2, 2: 3↓, ] } ``` ```swift let foo = [1, 2, 3↓,] + [4, 5, 6↓,] ``` ```swift let example = [ 1, 2↓, // 3, ] ``` ```swift let foo = ["אבג", "αβγ", "🇺🇸"↓,] ```
## Trailing Newline Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `trailing_newline` | Enabled | Yes | style | No | 3.0.0 Files should have a single trailing newline. ### Examples
Non Triggering Examples ```swift let a = 0 ```
Triggering Examples ```swift let a = 0 ``` ```swift let a = 0 ```
## Trailing Semicolon Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `trailing_semicolon` | Enabled | Yes | idiomatic | No | 3.0.0 Lines should not have trailing semicolons. ### Examples
Non Triggering Examples ```swift let a = 0 ```
Triggering Examples ```swift let a = 0↓; ``` ```swift let a = 0↓; let b = 1 ``` ```swift let a = 0↓;; ``` ```swift let a = 0↓; ;; ``` ```swift let a = 0↓; ; ; ```
## Trailing Whitespace Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `trailing_whitespace` | Enabled | Yes | style | No | 3.0.0 Lines should not have trailing whitespace. ### Examples
Non Triggering Examples ```swift let name: String ``` ```swift // ``` ```swift // ``` ```swift let name: String // ``` ```swift let name: String // ```
Triggering Examples ```swift let name: String ``` ```swift /* */ let name: String ```
## Type Body Length Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `type_body_length` | Enabled | No | metrics | No | 3.0.0 Type bodies should not span too many lines. ### Examples
Non Triggering Examples ```swift class Abc { let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 } ``` ```swift class Abc { } ``` ```swift class Abc { // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment } ``` ```swift class Abc { let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 /* this is a multiline comment */ } ``` ```swift struct Abc { let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 } ``` ```swift struct Abc { } ``` ```swift struct Abc { // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment } ``` ```swift struct Abc { let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 /* this is a multiline comment */ } ``` ```swift enum Abc { let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 } ``` ```swift enum Abc { } ``` ```swift enum Abc { // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment // this is a comment } ``` ```swift enum Abc { let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 /* this is a multiline comment */ } ```
Triggering Examples ```swift ↓class Abc { let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 } ``` ```swift ↓struct Abc { let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 } ``` ```swift ↓enum Abc { let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 let abc = 0 } ```
## Type Name Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `type_name` | Enabled | No | idiomatic | No | 3.0.0 Type name should only contain alphanumeric characters, start with an uppercase character and span between 3 and 40 characters in length. ### Examples
Non Triggering Examples ```swift class MyType {} ``` ```swift private class _MyType {} ``` ```swift class AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA {} ``` ```swift struct MyType {} ``` ```swift private struct _MyType {} ``` ```swift struct AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA {} ``` ```swift enum MyType {} ``` ```swift private enum _MyType {} ``` ```swift enum AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA {} ``` ```swift typealias Foo = Void ``` ```swift private typealias Foo = Void ``` ```swift protocol Foo { associatedtype Bar } ``` ```swift protocol Foo { associatedtype Bar: Equatable } ``` ```swift enum MyType { case value } ```
Triggering Examples ```swift class ↓myType {} ``` ```swift class ↓_MyType {} ``` ```swift private class ↓MyType_ {} ``` ```swift class ↓My {} ``` ```swift class ↓AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA {} ``` ```swift struct ↓myType {} ``` ```swift struct ↓_MyType {} ``` ```swift private struct ↓MyType_ {} ``` ```swift struct ↓My {} ``` ```swift struct ↓AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA {} ``` ```swift enum ↓myType {} ``` ```swift enum ↓_MyType {} ``` ```swift private enum ↓MyType_ {} ``` ```swift enum ↓My {} ``` ```swift enum ↓AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA {} ``` ```swift typealias ↓X = Void ``` ```swift private typealias ↓Foo_Bar = Void ``` ```swift private typealias ↓foo = Void ``` ```swift typealias ↓AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA = Void ``` ```swift protocol Foo { associatedtype ↓X } ``` ```swift protocol Foo { associatedtype ↓Foo_Bar: Equatable } ``` ```swift protocol Foo { associatedtype ↓AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA } ```
## Unavailable Function Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `unavailable_function` | Disabled | No | idiomatic | No | 4.1.0 Unimplemented functions should be marked as unavailable. ### Examples
Non Triggering Examples ```swift class ViewController: UIViewController { @available(*, unavailable) public required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } } ``` ```swift func jsonValue(_ jsonString: String) -> NSObject { let data = jsonString.data(using: .utf8)! let result = try! JSONSerialization.jsonObject(with: data, options: []) if let dict = (result as? [String: Any])?.bridge() { return dict } else if let array = (result as? [Any])?.bridge() { return array } fatalError() } ```
Triggering Examples ```swift class ViewController: UIViewController { public required ↓init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } } ``` ```swift class ViewController: UIViewController { public required ↓init?(coder aDecoder: NSCoder) { let reason = "init(coder:) has not been implemented" fatalError(reason) } } ```
## Unneeded Break in Switch Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `unneeded_break_in_switch` | Enabled | No | idiomatic | No | 3.0.0 Avoid using unneeded break statements. ### Examples
Non Triggering Examples ```swift switch foo { case .bar: break } ``` ```swift switch foo { default: break } ``` ```swift switch foo { case .bar: for i in [0, 1, 2] { break } } ``` ```swift switch foo { case .bar: if true { break } } ``` ```swift switch foo { case .bar: something() } ```
Triggering Examples ```swift switch foo { case .bar: something() ↓break } ``` ```swift switch foo { case .bar: something() ↓break // comment } ``` ```swift switch foo { default: something() ↓break } ``` ```swift switch foo { case .foo, .foo2 where condition: something() ↓break } ```
## Unneeded Parentheses in Closure Argument Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `unneeded_parentheses_in_closure_argument` | Disabled | Yes | style | No | 3.0.0 Parentheses are not needed when declaring closure arguments. ### Examples
Non Triggering Examples ```swift let foo = { (bar: Int) in } ``` ```swift let foo = { bar, _ in } ``` ```swift let foo = { bar in } ``` ```swift let foo = { bar -> Bool in return true } ```
Triggering Examples ```swift call(arg: { ↓(bar) in }) ``` ```swift call(arg: { ↓(bar, _) in }) ``` ```swift let foo = { ↓(bar) -> Bool in return true } ``` ```swift foo.map { ($0, $0) }.forEach { ↓(x, y) in } ``` ```swift foo.bar { [weak self] ↓(x, y) in } ``` ```swift [].first { ↓(temp) in [].first { ↓(temp) in [].first { ↓(temp) in _ = temp return false } return false } return false } ``` ```swift [].first { temp in [].first { ↓(temp) in [].first { ↓(temp) in _ = temp return false } return false } return false } ```
## Untyped Error in Catch Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `untyped_error_in_catch` | Disabled | Yes | idiomatic | No | 3.0.0 Catch statements should not declare error variables without type casting. ### Examples
Non Triggering Examples ```swift do { try foo() } catch {} ``` ```swift do { try foo() } catch Error.invalidOperation { } catch {} ``` ```swift do { try foo() } catch let error as MyError { } catch {} ``` ```swift do { try foo() } catch var error as MyError { } catch {} ```
Triggering Examples ```swift do { try foo() } ↓catch var error {} ``` ```swift do { try foo() } ↓catch let error {} ``` ```swift do { try foo() } ↓catch let someError {} ``` ```swift do { try foo() } ↓catch var someError {} ``` ```swift do { try foo() } ↓catch let e {} ``` ```swift do { try foo() } ↓catch(let error) {} ``` ```swift do { try foo() } ↓catch (let error) {} ```
## Unused Closure Parameter Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `unused_closure_parameter` | Enabled | Yes | lint | No | 3.0.0 Unused parameter in a closure should be replaced with _. ### Examples
Non Triggering Examples ```swift [1, 2].map { $0 + 1 } ``` ```swift [1, 2].map({ $0 + 1 }) ``` ```swift [1, 2].map { number in number + 1 } ``` ```swift [1, 2].map { _ in 3 } ``` ```swift [1, 2].something { number, idx in return number * idx } ``` ```swift let isEmpty = [1, 2].isEmpty() ``` ```swift violations.sorted(by: { lhs, rhs in return lhs.location > rhs.location }) ``` ```swift rlmConfiguration.migrationBlock.map { rlmMigration in return { migration, schemaVersion in rlmMigration(migration.rlmMigration, schemaVersion) } } ``` ```swift genericsFunc { (a: Type, b) in a + b } ``` ```swift var label: UILabel = { (lbl: UILabel) -> UILabel in lbl.backgroundColor = .red return lbl }(UILabel()) ``` ```swift hoge(arg: num) { num in return num } ``` ```swift ({ (manager: FileManager) in print(manager) })(FileManager.default) ``` ```swift withPostSideEffect { input in if true { print("\(input)") } } ```
Triggering Examples ```swift [1, 2].map { ↓number in return 3 } ``` ```swift [1, 2].map { ↓number in return numberWithSuffix } ``` ```swift [1, 2].map { ↓number in return 3 // number } ``` ```swift [1, 2].map { ↓number in return 3 "number" } ``` ```swift [1, 2].something { number, ↓idx in return number } ``` ```swift genericsFunc { (↓number: TypeA, idx: TypeB) in return idx } ``` ```swift hoge(arg: num) { ↓num in } ``` ```swift fooFunc { ↓아 in } ``` ```swift func foo () { bar { ↓number in return 3 } ```
## Unused Enumerated Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `unused_enumerated` | Enabled | No | idiomatic | No | 3.0.0 When the index or the item is not used, `.enumerated()` can be removed. ### Examples
Non Triggering Examples ```swift for (idx, foo) in bar.enumerated() { } ``` ```swift for (_, foo) in bar.enumerated().something() { } ``` ```swift for (_, foo) in bar.something() { } ``` ```swift for foo in bar.enumerated() { } ``` ```swift for foo in bar { } ``` ```swift for (idx, _) in bar.enumerated().something() { } ``` ```swift for (idx, _) in bar.something() { } ``` ```swift for idx in bar.indices { } ``` ```swift for (section, (event, _)) in data.enumerated() {} ```
Triggering Examples ```swift for (↓_, foo) in bar.enumerated() { } ``` ```swift for (↓_, foo) in abc.bar.enumerated() { } ``` ```swift for (↓_, foo) in abc.something().enumerated() { } ``` ```swift for (idx, ↓_) in bar.enumerated() { } ```
## Unused Import Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `unused_import` | Disabled | Yes | lint | Yes | 3.0.0 All imported modules should be required to make the file compile. ### Examples
Non Triggering Examples ```swift import Dispatch dispatchMain() ```
Triggering Examples ```swift ↓import Dispatch struct A { static func dispatchMain() {} } A.dispatchMain() ``` ```swift ↓import Foundation dispatchMain() ```
## Unused Optional Binding Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `unused_optional_binding` | Enabled | No | style | No | 3.0.0 Prefer `!= nil` over `let _ =` ### Examples
Non Triggering Examples ```swift if let bar = Foo.optionalValue { } ``` ```swift if let (_, second) = getOptionalTuple() { } ``` ```swift if let (_, asd, _) = getOptionalTuple(), let bar = Foo.optionalValue { } ``` ```swift if foo() { let _ = bar() } ``` ```swift if foo() { _ = bar() } ``` ```swift if case .some(_) = self {} ``` ```swift if let point = state.find({ _ in true }) {} ```
Triggering Examples ```swift if let ↓_ = Foo.optionalValue { } ``` ```swift if let a = Foo.optionalValue, let ↓_ = Foo.optionalValue2 { } ``` ```swift guard let a = Foo.optionalValue, let ↓_ = Foo.optionalValue2 { } ``` ```swift if let (first, second) = getOptionalTuple(), let ↓_ = Foo.optionalValue { } ``` ```swift if let (first, _) = getOptionalTuple(), let ↓_ = Foo.optionalValue { } ``` ```swift if let (_, second) = getOptionalTuple(), let ↓_ = Foo.optionalValue { } ``` ```swift if let ↓(_, _, _) = getOptionalTuple(), let bar = Foo.optionalValue { } ``` ```swift func foo() { if let ↓_ = bar { } ``` ```swift if case .some(let ↓_) = self {} ```
## Unused Private Declaration Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `unused_private_declaration` | Disabled | No | lint | Yes | 3.0.0 Private declarations should be referenced in that file. ### Examples
Non Triggering Examples ```swift private let kConstant = 0 _ = kConstant ```
Triggering Examples ```swift private let ↓kConstant = 0 ```
## Valid IBInspectable Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `valid_ibinspectable` | Enabled | No | lint | No | 3.0.0 @IBInspectable should be applied to variables only, have its type explicit and be of a supported type ### Examples
Non Triggering Examples ```swift class Foo { @IBInspectable private var x: Int } ``` ```swift class Foo { @IBInspectable private var x: String? } ``` ```swift class Foo { @IBInspectable private var x: String! } ``` ```swift class Foo { @IBInspectable private var count: Int = 0 } ``` ```swift class Foo { private var notInspectable = 0 } ``` ```swift class Foo { private let notInspectable: Int } ``` ```swift class Foo { private let notInspectable: UInt8 } ```
Triggering Examples ```swift class Foo { @IBInspectable private ↓let count: Int } ``` ```swift class Foo { @IBInspectable private ↓var insets: UIEdgeInsets } ``` ```swift class Foo { @IBInspectable private ↓var count = 0 } ``` ```swift class Foo { @IBInspectable private ↓var count: Int? } ``` ```swift class Foo { @IBInspectable private ↓var count: Int! } ``` ```swift class Foo { @IBInspectable private ↓var x: ImplicitlyUnwrappedOptional } ``` ```swift class Foo { @IBInspectable private ↓var count: Optional } ``` ```swift class Foo { @IBInspectable private ↓var x: Optional } ``` ```swift class Foo { @IBInspectable private ↓var x: ImplicitlyUnwrappedOptional } ```
## Vertical Parameter Alignment Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `vertical_parameter_alignment` | Enabled | No | style | No | 3.0.0 Function parameters should be aligned vertically if they're in multiple lines in a declaration. ### Examples
Non Triggering Examples ```swift func validateFunction(_ file: File, kind: SwiftDeclarationKind, dictionary: [String: SourceKitRepresentable]) { } ``` ```swift func validateFunction(_ file: File, kind: SwiftDeclarationKind, dictionary: [String: SourceKitRepresentable]) -> [StyleViolation] ``` ```swift func foo(bar: Int) ``` ```swift func foo(bar: Int) -> String ``` ```swift func validateFunction(_ file: File, kind: SwiftDeclarationKind, dictionary: [String: SourceKitRepresentable]) -> [StyleViolation] ``` ```swift func validateFunction( _ file: File, kind: SwiftDeclarationKind, dictionary: [String: SourceKitRepresentable]) -> [StyleViolation] ``` ```swift func validateFunction( _ file: File, kind: SwiftDeclarationKind, dictionary: [String: SourceKitRepresentable] ) -> [StyleViolation] ``` ```swift func regex(_ pattern: String, options: NSRegularExpression.Options = [.anchorsMatchLines, .dotMatchesLineSeparators]) -> NSRegularExpression ``` ```swift func foo(a: Void, b: [String: String] = [:]) { } ``` ```swift func foo(data: (size: CGSize, identifier: String)) {} ```
Triggering Examples ```swift func validateFunction(_ file: File, kind: SwiftDeclarationKind, ↓dictionary: [String: SourceKitRepresentable]) { } ``` ```swift func validateFunction(_ file: File, kind: SwiftDeclarationKind, ↓dictionary: [String: SourceKitRepresentable]) { } ``` ```swift func validateFunction(_ file: File, ↓kind: SwiftDeclarationKind, ↓dictionary: [String: SourceKitRepresentable]) { } ```
## Vertical Parameter Alignment On Call Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `vertical_parameter_alignment_on_call` | Disabled | No | style | No | 3.0.0 Function parameters should be aligned vertically if they're in multiple lines in a method call. ### Examples
Non Triggering Examples ```swift foo(param1: 1, param2: bar param3: false, param4: true) ``` ```swift foo(param1: 1, param2: bar) ``` ```swift foo(param1: 1, param2: bar param3: false, param4: true) ``` ```swift foo( param1: 1 ) { _ in } ``` ```swift UIView.animate(withDuration: 0.4, animations: { blurredImageView.alpha = 1 }, completion: { _ in self.hideLoading() }) ``` ```swift UIView.animate(withDuration: 0.4, animations: { blurredImageView.alpha = 1 }, completion: { _ in self.hideLoading() }) ``` ```swift foo(param1: 1, param2: { _ in }, param3: false, param4: true) ``` ```swift foo({ _ in bar() }, completion: { _ in baz() } ) ``` ```swift foo(param1: 1, param2: [ 0, 1 ], param3: 0) ```
Triggering Examples ```swift foo(param1: 1, param2: bar ↓param3: false, param4: true) ``` ```swift foo(param1: 1, param2: bar ↓param3: false, param4: true) ``` ```swift foo(param1: 1, param2: bar ↓param3: false, ↓param4: true) ``` ```swift foo(param1: 1, ↓param2: { _ in }) ``` ```swift foo(param1: 1, param2: { _ in }, param3: 2, ↓param4: 0) ``` ```swift foo(param1: 1, param2: { _ in }, ↓param3: false, param4: true) ```
## Vertical Whitespace Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `vertical_whitespace` | Enabled | Yes | style | No | 3.0.0 Limit vertical whitespace to a single empty line. ### Examples
Non Triggering Examples ```swift let abc = 0 ``` ```swift let abc = 0 ``` ```swift /* bcs */ ``` ```swift // bca ```
Triggering Examples ```swift let aaaa = 0 ``` ```swift struct AAAA {} ``` ```swift class BBBB {} ```
## Void Return Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `void_return` | Enabled | Yes | style | No | 3.0.0 Prefer `-> Void` over `-> ()`. ### Examples
Non Triggering Examples ```swift let abc: () -> Void = {} ``` ```swift let abc: () -> (VoidVoid) = {} ``` ```swift func foo(completion: () -> Void) ``` ```swift let foo: (ConfigurationTests) -> () throws -> Void) ``` ```swift let foo: (ConfigurationTests) -> () throws -> Void) ``` ```swift let foo: (ConfigurationTests) ->() throws -> Void) ``` ```swift let foo: (ConfigurationTests) -> () -> Void) ```
Triggering Examples ```swift let abc: () -> ↓() = {} ``` ```swift let abc: () -> ↓(Void) = {} ``` ```swift let abc: () -> ↓( Void ) = {} ``` ```swift func foo(completion: () -> ↓()) ``` ```swift func foo(completion: () -> ↓( )) ``` ```swift func foo(completion: () -> ↓(Void)) ``` ```swift let foo: (ConfigurationTests) -> () throws -> ↓()) ```
## Weak Delegate Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `weak_delegate` | Enabled | No | lint | No | 3.0.0 Delegates should be weak to avoid reference cycles. ### Examples
Non Triggering Examples ```swift class Foo { weak var delegate: SomeProtocol? } ``` ```swift class Foo { weak var someDelegate: SomeDelegateProtocol? } ``` ```swift class Foo { weak var delegateScroll: ScrollDelegate? } ``` ```swift class Foo { var scrollHandler: ScrollDelegate? } ``` ```swift func foo() { var delegate: SomeDelegate } ``` ```swift class Foo { var delegateNotified: Bool? } ``` ```swift protocol P { var delegate: AnyObject? { get set } } ``` ```swift class Foo { protocol P { var delegate: AnyObject? { get set } } } ``` ```swift class Foo { var computedDelegate: ComputedDelegate { return bar() } } ```
Triggering Examples ```swift class Foo { ↓var delegate: SomeProtocol? } ``` ```swift class Foo { ↓var scrollDelegate: ScrollDelegate? } ```
## XCTFail Message Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `xctfail_message` | Enabled | No | idiomatic | No | 3.0.0 An XCTFail call should include a description of the assertion. ### Examples
Non Triggering Examples ```swift func testFoo() { XCTFail("bar") } ``` ```swift func testFoo() { XCTFail(bar) } ```
Triggering Examples ```swift func testFoo() { ↓XCTFail() } ``` ```swift func testFoo() { ↓XCTFail("") } ```
## Yoda condition rule Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version --- | --- | --- | --- | --- | --- `yoda_condition` | Disabled | No | lint | No | 3.0.0 The variable should be placed on the left, the constant on the right of a comparison operator. ### Examples
Non Triggering Examples ```swift if foo == 42 {} ``` ```swift if foo <= 42.42 {} ``` ```swift guard foo >= 42 else { return } ``` ```swift guard foo != "str str" else { return } ``` ```swift while foo < 10 { } ``` ```swift while foo > 1 { } ``` ```swift while foo + 1 == 2 ``` ```swift if optionalValue?.property ?? 0 == 2 ``` ```swift if foo == nil ```
Triggering Examples ```swift ↓if 42 == foo {} ``` ```swift ↓if 42.42 >= foo {} ``` ```swift ↓guard 42 <= foo else { return } ``` ```swift ↓guard "str str" != foo else { return } ``` ```swift ↓while 10 > foo { } ``` ```swift ↓while 1 < foo { } ``` ```swift ↓if nil == foo ```