Skip to content

Instantly share code, notes, and snippets.

@kdawgwilk
Last active November 13, 2018 13:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kdawgwilk/7bc936d8597bfaa6abf45513d7937d29 to your computer and use it in GitHub Desktop.
Save kdawgwilk/7bc936d8597bfaa6abf45513d7937d29 to your computer and use it in GitHub Desktop.
SwiftLint Rules Examples

Empty Count (empty_count)

Prefer checking isEmpty over comparing count to zero.

Non-triggering Examples:

Example #1

var count = 0

Example #2

[Int]().isEmpty

Example #3

[Int]().count > 1

Example #4

[Int]().count == 1

Triggering Examples (violation is marked with '↓'):

Example #1

[Int]().count == 0

Example #2

[Int]().count > 0

Example #3

[Int]().count != 0

Redundant Optional Initialization (redundant_optional_initialization)

Initializing an optional variable with nil is redundant.

Non-triggering Examples:

Example #1

var myVar: Int?

Example #2

let myVar: Int? = nil

Example #3

var myVar: Int? = 0

Example #4

func foo(bar: Int? = 0) { }

Example #5

var myVar: Optional<Int>

Example #6

let myVar: Optional<Int> = nil

Example #7

var myVar: Optional<Int> = 0

Example #8

var foo: Int? {
   if bar != nil { }
   return 0
}

Example #9

var foo: Int? = {
   if bar != nil { }
   return 0
}()

Triggering Examples (violation is marked with '↓'):

Example #1

var myVar: Int? = nil

Example #2

var myVar: Optional<Int> = nil

Example #3

var myVar: Int?↓=nil

Example #4

var myVar: Optional<Int>↓=nil

Trailing Semicolon (trailing_semicolon)

Lines should not have trailing semicolons.

Non-triggering Examples:

Example #1

let a = 0

Triggering Examples (violation is marked with '↓'):

Example #1

let a = 0;

Example #2

let a = 0;
let b = 1

Example #3

let a = 0;;

Example #4

let a = 0;    ;;

Example #5

let a = 0; ; ;

Statement Position (statement_position)

Else and catch should be on the same line, one space after the previous declaration.

Non-triggering Examples:

Example #1

} else if {

Example #2

} else {

Example #3

} catch {

Example #4

"}else{"

Example #5

struct A { let catchphrase: Int }
let a = A(
 catchphrase: 0
)

Example #6

struct A { let `catch`: Int }
let a = A(
 `catch`: 0
)

Triggering Examples (violation is marked with '↓'):

Example #1

}else if {

Example #2

}  else {

Example #3

}
catch {

Example #4

}
	  catch {

Type Name (type_name)

Type name should only contain alphanumeric characters, start with an uppercase character and span between 3 and 40 characters in length.

Non-triggering Examples:

Example #1

class MyType {}

Example #2

private class _MyType {}

Example #3

class AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA {}

Example #4

struct MyType {}

Example #5

private struct _MyType {}

Example #6

struct AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA {}

Example #7

enum MyType {}

Example #8

private enum _MyType {}

Example #9

enum AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA {}

Example #10

typealias Foo = Void

Example #11

private typealias Foo = Void

Example #12

protocol Foo {
 associatedtype Bar
 }

Example #13

protocol Foo {
 associatedtype Bar: Equatable
 }

Example #14

enum MyType {
case value
}

Triggering Examples (violation is marked with '↓'):

Example #1

class myType {}

Example #2

class _MyType {}

Example #3

private class MyType_ {}

Example #4

class My {}

Example #5

class AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA {}

Example #6

struct myType {}

Example #7

struct _MyType {}

Example #8

private struct MyType_ {}

Example #9

struct My {}

Example #10

struct AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA {}

Example #11

enum myType {}

Example #12

enum _MyType {}

Example #13

private enum MyType_ {}

Example #14

enum My {}

Example #15

enum AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA {}

Example #16

typealias X = Void

Example #17

private typealias Foo_Bar = Void

Example #18

private typealias foo = Void

Example #19

typealias AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA = Void

Example #20

protocol Foo {
 associatedtype X
 }

Example #21

protocol Foo {
 associatedtype Foo_Bar: Equatable
 }

Example #22

protocol Foo {
 associatedtype AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
 }

Unused Enumerated (unused_enumerated)

When the index or the item is not used, .enumerated() can be removed.

Non-triggering Examples:

Example #1

for (idx, foo) in bar.enumerated() { }

Example #2

for (_, foo) in bar.enumerated().something() { }

Example #3

for (_, foo) in bar.something() { }

Example #4

for foo in bar.enumerated() { }

Example #5

for foo in bar { }

Example #6

for (idx, _) in bar.enumerated().something() { }

Example #7

for (idx, _) in bar.something() { }

Example #8

for idx in bar.indices { }

Triggering Examples (violation is marked with '↓'):

Example #1

for (_, foo) in bar.enumerated() { }

Example #2

for (_, foo) in abc.bar.enumerated() { }

Example #3

for (_, foo) in abc.something().enumerated() { }

Example #4

for (idx, _) in bar.enumerated() { }

Todo (todo)

TODOs and FIXMEs should be avoided.

Non-triggering Examples:

Example #1

// notaTODO:

Example #2

// notaFIXME:

Triggering Examples (violation is marked with '↓'):

Example #1

// ↓TODO:

Example #2

// ↓FIXME:

Example #3

// ↓TODO(note)

Example #4

// ↓FIXME(note)

Example #5

/* ↓FIXME: */

Example #6

/* ↓TODO: */

Example #7

/** ↓FIXME: */

Example #8

/** ↓TODO: */

Explicit Type Interface (explicit_type_interface)

Properties should have a type interface

Non-triggering Examples:

Example #1

class Foo {
  var myVar: Int? = 0
}

Example #2

class Foo {
  let myVar: Int? = 0
}

Example #3

class Foo {
  static var myVar: Int? = 0
}

Example #4

class Foo {
  class var myVar: Int? = 0
}

Triggering Examples (violation is marked with '↓'):

Example #1

class Foo {
  var myVar = 0

}

Example #2

class Foo {
  let mylet = 0

}

Example #3

class Foo {
  static var myStaticVar = 0
}

Example #4

class Foo {
  class var myClassVar = 0
}

Legacy Constant (legacy_constant)

Struct-scoped constants are preferred over legacy global constants.

Non-triggering Examples:

Example #1

CGRect.infinite

Example #2

CGPoint.zero

Example #3

CGRect.zero

Example #4

CGSize.zero

Example #5

NSPoint.zero

Example #6

NSRect.zero

Example #7

NSSize.zero

Example #8

CGRect.null

Example #9

CGFloat.pi

Example #10

Float.pi

Triggering Examples (violation is marked with '↓'):

Example #1

CGRectInfinite

Example #2

CGPointZero

Example #3

CGRectZero

Example #4

CGSizeZero

Example #5

NSZeroPoint

Example #6

NSZeroRect

Example #7

NSZeroSize

Example #8

CGRectNull

Example #9

CGFloat(M_PI)

Example #10

Float(M_PI)

Force Cast (force_cast)

Force casts should be avoided.

Non-triggering Examples:

Example #1

NSNumber() as? Int

Triggering Examples (violation is marked with '↓'):

Example #1

NSNumber() as! Int

Nimble Operator (nimble_operator)

Prefer Nimble operator overloads over free matcher functions.

Non-triggering Examples:

Example #1

expect(seagull.squawk) != "Hi!"

Example #2

expect("Hi!") == "Hi!"

Example #3

expect(10) > 2

Example #4

expect(10) >= 10

Example #5

expect(10) < 11

Example #6

expect(10) <= 10

Example #7

expect(x) === x

Example #8

expect(10) == 10

Example #9

expect(object.asyncFunction()).toEventually(equal(1))

Example #10

expect(actual).to(haveCount(expected))

Triggering Examples (violation is marked with '↓'):

Example #1

expect(seagull.squawk).toNot(equal("Hi"))

Example #2

expect(12).toNot(equal(10))

Example #3

expect(10).to(equal(10))

Example #4

expect(10).to(beGreaterThan(8))

Example #5

expect(10).to(beGreaterThanOrEqualTo(10))

Example #6

expect(10).to(beLessThan(11))

Example #7

expect(10).to(beLessThanOrEqualTo(10))

Example #8

expect(x).to(beIdenticalTo(x))

Example #9

expect(10) > 2
 expect(10).to(beGreaterThan(2))

Unused Closure Parameter (unused_closure_parameter)

Unused parameter in a closure should be replaced with _.

Non-triggering Examples:

Example #1

[1, 2].map { $0 + 1 }

Example #2

[1, 2].map({ $0 + 1 })

Example #3

[1, 2].map { number in
 number + 1 
}

Example #4

[1, 2].map { _ in
 3 
}

Example #5

[1, 2].something { number, idx in
 return number * idx
}

Example #6

let isEmpty = [1, 2].isEmpty()

Example #7

violations.sorted(by: { lhs, rhs in 
 return lhs.location > rhs.location
})

Example #8

rlmConfiguration.migrationBlock.map { rlmMigration in
return { migration, schemaVersion in
rlmMigration(migration.rlmMigration, schemaVersion)
}
}

Example #9

genericsFunc { (a: Type, b) in
a + b
}

Example #10

var label: UILabel = { (lbl: UILabel) -> UILabel in
   lbl.backgroundColor = .red
   return lbl
}(UILabel())

Example #11

hoge(arg: num) { num in
  return num
}

Triggering Examples (violation is marked with '↓'):

Example #1

[1, 2].map { number in
 return 3
}

Example #2

[1, 2].map { number in
 return numberWithSuffix
}

Example #3

[1, 2].map { number in
 return 3 // number
}

Example #4

[1, 2].map { number in
 return 3 "number"
}

Example #5

[1, 2].something { number, ↓idx in
 return number
}

Example #6

genericsFunc { (number: TypeA, idx: TypeB) in return idx
}

Example #7

hoge(arg: num) { num in
}

Number Separator (number_separator)

Underscores should be used as thousand separator in large decimal numbers.

Non-triggering Examples:

Example #1

let foo = -100

Example #2

let foo = -1_000

Example #3

let foo = -1_000_000

Example #4

let foo = -1.000_1

Example #5

let foo = -1_000_000.000_000_1

Example #6

let binary = -0b10000

Example #7

let binary = -0b1000_0001

Example #8

let hex = -0xA

Example #9

let hex = -0xAA_BB

Example #10

let octal = -0o21

Example #11

let octal = -0o21_1

Example #12

let exp = -1_000_000.000_000e2

Example #13

let foo = +100

Example #14

let foo = +1_000

Example #15

let foo = +1_000_000

Example #16

let foo = +1.000_1

Example #17

let foo = +1_000_000.000_000_1

Example #18

let binary = +0b10000

Example #19

let binary = +0b1000_0001

Example #20

let hex = +0xA

Example #21

let hex = +0xAA_BB

Example #22

let octal = +0o21

Example #23

let octal = +0o21_1

Example #24

let exp = +1_000_000.000_000e2

Example #25

let foo = 100

Example #26

let foo = 1_000

Example #27

let foo = 1_000_000

Example #28

let foo = 1.000_1

Example #29

let foo = 1_000_000.000_000_1

Example #30

let binary = 0b10000

Example #31

let binary = 0b1000_0001

Example #32

let hex = 0xA

Example #33

let hex = 0xAA_BB

Example #34

let octal = 0o21

Example #35

let octal = 0o21_1

Example #36

let exp = 1_000_000.000_000e2

Triggering Examples (violation is marked with '↓'):

Example #1

let foo = ↓-10_0

Example #2

let foo = ↓-1000

Example #3

let foo = ↓-1000e2

Example #4

let foo = ↓-1000E2

Example #5

let foo = ↓-1__000

Example #6

let foo = ↓-1.0001

Example #7

let foo = ↓-1_000_000.000000_1

Example #8

let foo = ↓-1000000.000000_1

Example #9

let foo = +↓10_0

Example #10

let foo = +↓1000

Example #11

let foo = +↓1000e2

Example #12

let foo = +↓1000E2

Example #13

let foo = +↓1__000

Example #14

let foo = +↓1.0001

Example #15

let foo = +↓1_000_000.000000_1

Example #16

let foo = +↓1000000.000000_1

Example #17

let foo = 10_0

Example #18

let foo = 1000

Example #19

let foo = 1000e2

Example #20

let foo = 1000E2

Example #21

let foo = 1__000

Example #22

let foo = 1.0001

Example #23

let foo = 1_000_000.000000_1

Example #24

let foo = 1000000.000000_1

Comma Spacing (comma)

There should be no space before and one after any comma.

Non-triggering Examples:

Example #1

func abc(a: String, b: String) { }

Example #2

abc(a: "string", b: "string"

Example #3

enum a { case a, b, c }

Example #4

func abc(
  a: String,  // comment
  bcd: String // comment
) {
}

Example #5

func abc(
  a: String,
  bcd: String
) {
}

Triggering Examples (violation is marked with '↓'):

Example #1

func abc(a: String ,b: String) { }

Example #2

func abc(a: String ,b: String ,c: String ,d: String) { }

Example #3

abc(a: "string",b: "string"

Example #4

enum a { case a ,b }

Example #5

let result = plus(
    first: 3 , // #683
    second: 4
)

Sorted Imports (sorted_imports)

Imports should be sorted.

Non-triggering Examples:

Example #1

import AAA
import BBB
import CCC
import DDD

Example #2

import Alamofire
import API

Example #3

import labc
import Ldef

Triggering Examples (violation is marked with '↓'):

Example #1

import AAA
import ZZZ
import BBB
import CCC

Implicit Getter (implicit_getter)

Computed read-only properties should avoid using the get keyword.

Non-triggering Examples:

Example #1

class Foo {
  var foo: Int {
 get {
 return 3
}
 set {
 _abc = newValue 
}
}
}

Example #2

class Foo {
  var foo: Int {
 return 20 
} 
}
}

Example #3

class Foo {
  static var foo: Int {
 return 20 
} 
}
}

Example #4

class Foo {
  static foo: Int {
 get {
 return 3
}
 set {
 _abc = newValue 
}
}
}

Example #5

class Foo {
  var foo: Int
}

Example #6

class Foo {
  var foo: Int {
 return getValueFromDisk() 
} 
}
}

Example #7

class Foo {
  var foo: String {
 return "get" 
} 
}
}

Example #8

protocol Foo {
 var foo: Int { get }

Example #9

protocol Foo {
 var foo: Int { get set }

Example #10

class Foo {
  var foo: Int {
    struct Bar {
      var bar: Int {
        get { return 1 }
        set { _ = newValue }
      }
    }
    return Bar().bar
  }
}

Triggering Examples (violation is marked with '↓'):

Example #1

class Foo {
  var foo: Int {
 get {
 return 20 
} 
} 
}
}

Example #2

class Foo {
  var foo: Int {
 get{
 return 20 
} 
} 
}
}

Example #3

class Foo {
  static var foo: Int {
 get {
 return 20 
} 
} 
}
}

Example #4

var foo: Int {
 get {
 return 20 
} 
} 
}

Legacy CGGeometry Functions (legacy_cggeometry_functions)

Struct extension properties and methods are preferred over legacy functions

Non-triggering Examples:

Example #1

rect.width

Example #2

rect.height

Example #3

rect.minX

Example #4

rect.midX

Example #5

rect.maxX

Example #6

rect.minY

Example #7

rect.midY

Example #8

rect.maxY

Example #9

rect.isNull

Example #10

rect.isEmpty

Example #11

rect.isInfinite

Example #12

rect.standardized

Example #13

rect.integral

Example #14

rect.insetBy(dx: 5.0, dy: -7.0)

Example #15

rect.offsetBy(dx: 5.0, dy: -7.0)

Example #16

rect1.union(rect2)

Example #17

rect1.intersect(rect2)

Example #18

rect1.contains(rect2)

Example #19

rect.contains(point)

Example #20

rect1.intersects(rect2)

Triggering Examples (violation is marked with '↓'):

Example #1

CGRectGetWidth(rect)

Example #2

CGRectGetHeight(rect)

Example #3

CGRectGetMinX(rect)

Example #4

CGRectGetMidX(rect)

Example #5

CGRectGetMaxX(rect)

Example #6

CGRectGetMinY(rect)

Example #7

CGRectGetMidY(rect)

Example #8

CGRectGetMaxY(rect)

Example #9

CGRectIsNull(rect)

Example #10

CGRectIsEmpty(rect)

Example #11

CGRectIsInfinite(rect)

Example #12

CGRectStandardize(rect)

Example #13

CGRectIntegral(rect)

Example #14

CGRectInset(rect, 10, 5)

Example #15

CGRectOffset(rect, -2, 8.3)

Example #16

CGRectUnion(rect1, rect2)

Example #17

CGRectIntersection(rect1, rect2)

Example #18

CGRectContainsRect(rect1, rect2)

Example #19

CGRectContainsPoint(rect, point)

Example #20

CGRectIntersectsRect(rect1, rect2)

Force Unwrapping (force_unwrapping)

Force unwrapping should be avoided.

Non-triggering Examples:

Example #1

if let url = NSURL(string: query)

Example #2

navigationController?.pushViewController(viewController, animated: true)

Example #3

let s as! Test

Example #4

try! canThrowErrors()

Example #5

let object: Any!

Example #6

@IBOutlet var constraints: [NSLayoutConstraint]!

Example #7

setEditing(!editing, animated: true)

Example #8

navigationController.setNavigationBarHidden(!navigationController.navigationBarHidden, animated: true)

Example #9

if addedToPlaylist && (!self.selectedFilters.isEmpty || self.searchBar?.text?.isEmpty == false) {}

Example #10

print("\(xVar)!")

Example #11

var test = (!bar)

Triggering Examples (violation is marked with '↓'):

Example #1

let url = NSURL(string: query)↓!

Example #2

navigationController↓!.pushViewController(viewController, animated: true)

Example #3

let unwrapped = optional↓!

Example #4

return cell↓!

Example #5

let url = NSURL(string: "http://www.google.com")↓!

Example #6

let dict = ["Boooo": "👻"]func bla() -> String { return dict["Boooo"]↓! }

Leading Whitespace (leading_whitespace)

Files should not contain leading whitespace.

Non-triggering Examples:

Example #1

//

Triggering Examples (violation is marked with '↓'):

Example #1

Example #2

 //

Cyclomatic Complexity (cyclomatic_complexity)

Complexity of function bodies should be limited.

Non-triggering Examples:

Example #1

func f1() {
if true {
for _ in 1..5 { } }
if false { }
}

Example #2

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}}

Example #3

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 (violation is marked with '↓'):

Example #1

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
    }
  }
}

Control Statement (control_statement)

if,for,while,do statements shouldn't wrap their conditionals in parentheses.

Non-triggering Examples:

Example #1

if condition {

Example #2

if (a, b) == (0, 1) {

Example #3

if (a || b) && (c || d) {

Example #4

if (min...max).contains(value) {

Example #5

if renderGif(data) {

Example #6

renderGif(data)

Example #7

for item in collection {

Example #8

for (key, value) in dictionary {

Example #9

for (index, value) in enumerate(array) {

Example #10

for var index = 0; index < 42; index++ {

Example #11

guard condition else {

Example #12

while condition {

Example #13

} while condition {

Example #14

do { ; } while condition {

Example #15

switch foo {

Triggering Examples (violation is marked with '↓'):

Example #1

if (condition) {

Example #2

if(condition) {

Example #3

if ((a || b) && (c || d)) {

Example #4

if ((min...max).contains(value)) {

Example #5

for (item in collection) {

Example #6

for (var index = 0; index < 42; index++) {

Example #7

for(item in collection) {

Example #8

for(var index = 0; index < 42; index++) {

Example #9

guard (condition) else {

Example #10

while (condition) {

Example #11

while(condition) {

Example #12

} while (condition) {

Example #13

} while(condition) {

Example #14

do { ; } while(condition) {

Example #15

do { ; } while (condition) {

Example #16

switch (foo) {

Function Body Length (function_body_length)

Functions bodies should not span too many lines.

Non-triggering Examples:

Triggering Examples (violation is marked with '↓'):

Empty Parentheses with Trailing Closure (empty_parentheses_with_trailing_closure)

When using trailing closures, empty parentheses should be avoided after the method call.

Non-triggering Examples:

Example #1

[1, 2].map { $0 + 1 }

Example #2

[1, 2].map({ $0 + 1 })

Example #3

[1, 2].reduce(0) { $0 + $1 }

Example #4

[1, 2].map { number in
 number + 1 
}

Example #5

let isEmpty = [1, 2].isEmpty()

Example #6

UIView.animateWithDuration(0.3, animations: {
   self.disableInteractionRightView.alpha = 0
}, completion: { _ in
   ()
})

Triggering Examples (violation is marked with '↓'):

Example #1

[1, 2].map() { $0 + 1 }

Example #2

[1, 2].map( ) { $0 + 1 }

Example #3

[1, 2].map() { number in
 number + 1 
}

Example #4

[1, 2].map(  ) { number in
 number + 1 
}

Dynamic Inline (dynamic_inline)

avoid using 'dynamic' and '@inline(__always)' together.

Non-triggering Examples:

Example #1

class C {
dynamic func f() {}}

Example #2

class C {
@inline(__always) func f() {}}

Example #3

class C {
@inline(never) dynamic func f() {}}

Triggering Examples (violation is marked with '↓'):

Example #1

class C {
@inline(__always) dynamic func f() {}
}

Example #2

class C {
@inline(__always) public dynamic func f() {}
}

Example #3

class C {
@inline(__always) dynamic internal func f() {}
}

Example #4

class C {
@inline(__always)
dynamic func f() {}
}

Example #5

class C {
@inline(__always)
dynamic
func f() {}
}

Type Body Length (type_body_length)

Type bodies should not span too many lines.

Non-triggering Examples:

Example #1

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
}

Example #2

class Abc {









































































































































































































}

Example #3

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
}

Example #4

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
*/
}

Example #5

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
}

Example #6

struct Abc {









































































































































































































}

Example #7

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
}

Example #8

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
*/
}

Example #9

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
}

Example #10

enum Abc {









































































































































































































}

Example #11

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
}

Example #12

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 (violation is marked with '↓'):

Example #1

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
}

Example #2

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
}

Example #3

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
}

Unused Optional Binding (unused_optional_binding)

Prefer != nil over let _ =

Non-triggering Examples:

Example #1

if let bar = Foo.optionalValue {
}

Example #2

if let (_, second) = getOptionalTuple() {
}

Example #3

if let (_, asd, _) = getOptionalTuple(), let bar = Foo.optionalValue {
}

Example #4

if foo() { let _ = bar() }

Example #5

if foo() { _ = bar() }

Example #6

if case .some(_) = self {}

Example #7

if let point = state.find({ _ in true }) {}

Triggering Examples (violation is marked with '↓'):

Example #1

if let _ = Foo.optionalValue {
}

Example #2

if let a = Foo.optionalValue, let ↓_ = Foo.optionalValue2 {
}

Example #3

guard let a = Foo.optionalValue, let ↓_ = Foo.optionalValue2 {
}

Example #4

if let (first, second) = getOptionalTuple(), let ↓_ = Foo.optionalValue {
}

Example #5

if let (first, _) = getOptionalTuple(), let ↓_ = Foo.optionalValue {
}

Example #6

if let (_, second) = getOptionalTuple(), let ↓_ = Foo.optionalValue {
}

Example #7

if let (_, _, _) = getOptionalTuple(), let bar = Foo.optionalValue {
}

Example #8

func foo() {
if let _ = bar {
}

Example #9

if case .some(let ↓_) = self {}

Operator Function Whitespace (operator_whitespace)

Operators should be surrounded by a single whitespace when defining them.

Non-triggering Examples:

Example #1

func <| (lhs: Int, rhs: Int) -> Int {}

Example #2

func <|< <A>(lhs: A, rhs: A) -> A {}

Example #3

func abc(lhs: Int, rhs: Int) -> Int {}

Triggering Examples (violation is marked with '↓'):

Example #1

func <|(lhs: Int, rhs: Int) -> Int {}

Example #2

func <|<<A>(lhs: A, rhs: A) -> A {}

Example #3

func <|  (lhs: Int, rhs: Int) -> Int {}

Example #4

func <|<  <A>(lhs: A, rhs: A) -> A {}

Example #5

func  <| (lhs: Int, rhs: Int) -> Int {}

Example #6

func  <|< <A>(lhs: A, rhs: A) -> A {}

Closure Spacing (closure_spacing)

Closure expressions should have a single space inside each brace.

Non-triggering Examples:

Example #1

[].map ({ $0.description })

Example #2

[].filter { $0.contains(location) }

Example #3

extension UITableViewCell: ReusableView { }

Example #4

extension UITableViewCell: ReusableView {}

Triggering Examples (violation is marked with '↓'):

Example #1

[].filter({$0.contains(location)})

Example #2

[].map({$0})

Prohibited calls to super (prohibited_super_call)

Some methods should not call super

Non-triggering Examples:

Example #1

class VC: UIViewController {
	override func loadView() {
	}
}

Example #2

class NSView {
	func updateLayer() {
		self.method1()	}
}

Triggering Examples (violation is marked with '↓'):

Example #1

class VC: UIViewController {
	override func loadView() {
		super.loadView()
	}
}

Example #2

class VC: NSFileProviderExtension {
	override func providePlaceholder(at url: URL,completionHandler: @escaping (Error?) -> Void){
		self.method1()
		super.providePlaceholder(at:url, completionHandler: completionHandler)
	}
}

Example #3

class VC: NSView {
	override func updateLayer() {
		self.method1()
		super.updateLayer()
		self.method2()
	}
}

Object Literal (object_literal)

Prefer object literals over image and color inits.

Non-triggering Examples:

Example #1

let image = #imageLiteral(resourceName: "image.jpg")

Example #2

let color = #colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)

Example #3

let image = UIImage(named: aVariable)

Example #4

let image = UIImage(named: "interpolated \(variable)")

Example #5

let color = UIColor(red: value, green: value, blue: value, alpha: 1)

Example #6

let image = NSImage(named: aVariable)

Example #7

let image = NSImage(named: "interpolated \(variable)")

Example #8

let color = NSColor(red: value, green: value, blue: value, alpha: 1)

Triggering Examples (violation is marked with '↓'):

Example #1

let image = UIImage(named: "foo")

Example #2

let color = UIColor(red: 0.3, green: 0.3, blue: 0.3, alpha: 1)

Example #3

let color = UIColor(red: 100 / 255.0, green: 50 / 255.0, blue: 0, alpha: 1)

Example #4

let color = UIColor(white: 0.5, alpha: 1)

Example #5

let image = NSImage(named: "foo")

Example #6

let color = NSColor(red: 0.3, green: 0.3, blue: 0.3, alpha: 1)

Example #7

let color = NSColor(red: 100 / 255.0, green: 50 / 255.0, blue: 0, alpha: 1)

Example #8

let color = NSColor(white: 0.5, alpha: 1)

Example #9

let image = UIImage.init(named: "foo")

Example #10

let color = UIColor.init(red: 0.3, green: 0.3, blue: 0.3, alpha: 1)

Example #11

let color = UIColor.init(red: 100 / 255.0, green: 50 / 255.0, blue: 0, alpha: 1)

Example #12

let color = UIColor.init(white: 0.5, alpha: 1)

Example #13

let image = NSImage.init(named: "foo")

Example #14

let color = NSColor.init(red: 0.3, green: 0.3, blue: 0.3, alpha: 1)

Example #15

let color = NSColor.init(red: 100 / 255.0, green: 50 / 255.0, blue: 0, alpha: 1)

Example #16

let color = NSColor.init(white: 0.5, alpha: 1)

Valid Docs (valid_docs)

Documented declarations should be valid.

Non-triggering Examples:

Example #1

/// docs
public func a() {}

Example #2

/// docs
/// - parameter param: this is void
public func a(param: Void) {}

Example #3

/// docs
/// - parameter label: this is void
public func a(label param: Void) {}

Example #4

/// docs
/// - parameter param: this is void
public func a(label param: Void) {}

Example #5

/// docs
/// - Parameter param: this is void
public func a(label param: Void) {}

Example #6

/// docs
/// - returns: false
public func no() -> Bool { return false }

Example #7

/// docs
/// - Returns: false
public func no() -> Bool { return false }

Example #8

/// Returns false
public func no() -> Bool { return false }

Example #9

/// Returns false
var no: Bool { return false }

Example #10

/// docs
var no: Bool { return false }

Example #11

/// docs
/// - throws: NSError
func a() throws {}

Example #12

/// docs
/// - Throws: NSError
func a() throws {}

Example #13

/// docs
/// - parameter param: this is void
/// - returns: false
public func no(param: (Void -> Void)?) -> Bool { return false }

Example #14

/// docs
/// - parameter param: this is void
///- parameter param2: this is void too
/// - returns: false

Example #15

public func no(param: (Void -> Void)?, param2: String->Void) -> Bool {return false}

Example #16

/// docs
/// - parameter param: this is void
public func no(param: (Void -> Void)?) {}

Example #17

/// docs
/// - parameter param: this is void
///- parameter param2: this is void too
public func no(param: (Void -> Void)?, param2: String->Void) {}

Example #18

/// docs👨‍👩‍👧‍👧
/// - returns: false
public func no() -> Bool { return false }

Example #19

/// docs
/// - returns: tuple
public func no() -> (Int, Int) {return (1, 2)}

Example #20

/// docs
/// - returns: closure
public func no() -> (Void->Void) {}

Example #21

/// docs
/// - parameter param: this is void
/// - parameter param2: this is void too
func no(param: (Void) -> Void, onError param2: ((NSError) -> Void)? = nil) {}

Example #22

/// docs
/// - parameter param: this is a void closure
/// - parameter param2: this is a void closure too
/// - parameter param3: this is a void closure too
func a(param: () -> Void, param2: (parameter: Int) -> Void, param3: (parameter: Int) -> Void) {}

Example #23

/// docs
/// - parameter param: this is a void closure
/// - Parameter param2: this is a void closure too
/// - Parameter param3: this is a void closure too
func a(param: () -> Void, param2: (parameter: Int) -> Void, param3: (parameter: Int) -> Void) {}

Example #24

/// docs
/// - parameter param: this is a void closure
/// - returns: Foo<Void>
func a(param: () -> Void) -> Foo<Void> {return Foo<Void>}

Example #25

/// docs
/// - parameter param: this is a void closure
/// - returns: Foo<Void>
func a(param: () -> Void) -> Foo<[Int]> {return Foo<[Int]>}

Example #26

/// docs
/// - throws: NSError
/// - returns: false
func a() throws -> Bool { return true }

Example #27

/// docs
/// - parameter param: this is a closure
/// - returns: Bool
func a(param: (Void throws -> Bool)) -> Bool { return true }

Triggering Examples (violation is marked with '↓'):

Example #1

/// docs
public func a(param: Void) {}

Example #2

/// docs
/// - parameter invalid: this is void
public func a(param: Void) {}

Example #3

/// docs
/// - parameter invalid: this is void
public func a(label param: Void) {}

Example #4

/// docs
/// - parameter invalid: this is void
public func a() {}

Example #5

/// docs
public func no() -> Bool { return false }

Example #6

/// Returns false
public func a() {}

Example #7

/// docs
/// - throws: NSError
func a() {}

Example #8

/// docs
func a() throws {}

Example #9

/// docs
/// - parameter param: this is void
public func no(param: (Void -> Void)?) -> Bool { return false }

Example #10

/// docs
/// - parameter param: this is void
///- parameter param2: this is void too
public func no(param: (Void -> Void)?, param2: String->Void) -> Bool {return false}

Example #11

/// docs
/// - parameter param: this is void
/// - returns: false
public func no(param: (Void -> Void)?) {}

Example #12

/// docs
/// - parameter param: this is void
///- parameter param2: this is void too
/// - returns: false
public func no(param: (Void -> Void)?, param2: String->Void) {}

Example #13

/// docs
public func no() -> (Int, Int) {return (1, 2)}

Example #14

/// docs
/// - parameter param: this is void
///- parameter param2: this is void too
///- returns: closure
func no(param: (Void) -> Void, onError param2: ((NSError) -> Void)? = nil) {}

Example #15

/// docs
/// - parameter param: this is a void closure
func a(param: () -> Void) -> Foo<Void> {return Foo<Void>}

Example #16

/// docs
/// - parameter param: this is a void closure
func a(param: () -> Void) -> Foo<[Int]> {return Foo<[Int]>}

Example #17

/// docs
func a() throws -> Bool { return true }

Vertical Whitespace (vertical_whitespace)

Limit vertical whitespace to a single empty line.

Non-triggering Examples:

Example #1

let abc = 0

Example #2

let abc = 0

Example #3

/* bcs 



*/

Example #4

// bca 

Triggering Examples (violation is marked with '↓'):

Example #1

let aaaa = 0

Example #2

struct AAAA {}


Example #3

class BBBB {}

Redundant Void Return (redundant_void_return)

Returning Void in a function declaration is redundant.

Non-triggering Examples:

Example #1

func foo() {}

Example #2

func foo() -> Int {}

Example #3

func foo() -> Int -> Void {}

Example #4

func foo() -> VoidResponse

Example #5

let foo: Int -> Void

Example #6

func foo() -> Int -> () {}

Example #7

let foo: Int -> ()

Triggering Examples (violation is marked with '↓'):

Example #1

func foo() -> Void {}

Example #2

protocol Foo {
 func foo() -> Void
}

Example #3

func foo() -> () {}

Example #4

protocol Foo {
 func foo() -> ()
}

Large Tuple (large_tuple)

Tuples shouldn't have too many members. Create a custom type instead.

Non-triggering Examples:

Example #1

let foo: (Int, Int)

Example #2

let foo: (start: Int, end: Int)

Example #3

let foo: (Int, (Int, String))

Example #4

func foo() -> (Int, Int)

Example #5

func foo() -> (Int, Int) {}

Example #6

func foo(bar: String) -> (Int, Int)

Example #7

func foo(bar: String) -> (Int, Int) {}

Example #8

func foo() throws -> (Int, Int)

Example #9

func foo() throws -> (Int, Int) {}

Example #10

let foo: (Int, Int, Int) -> Void

Example #11

var completionHandler: ((_ data: Data?, _ resp: URLResponse?, _ e: NSError?) -> Void)!

Example #12

func getDictionaryAndInt() -> (Dictionary<Int, String>, Int)?

Example #13

func getGenericTypeAndInt() -> (Type<Int, String, Float>, Int)?

Triggering Examples (violation is marked with '↓'):

Example #1

let foo: (Int, Int, Int)

Example #2

let foo: (start: Int, end: Int, value: String)

Example #3

let foo: (Int, (Int, Int, Int))

Example #4

func foo(bar: (Int, Int, Int))

Example #5

func foo() ->(Int, Int, Int)

Example #6

func foo() ->(Int, Int, Int) {}

Example #7

func foo(bar: String) ->(Int, Int, Int)

Example #8

func foo(bar: String) ->(Int, Int, Int) {}

Example #9

func foo() throws ->(Int, Int, Int)

Example #10

func foo() throws ->(Int, Int, Int) {}

Example #11

func foo() throws ->(Int,(String, String, String), Int) {}

Example #12

func getDictionaryAndInt() -> (Dictionary<Int,(String, String, String)>, Int)?

Trailing Whitespace (trailing_whitespace)

Lines should not have trailing whitespace.

Non-triggering Examples:

Example #1

let name: String

Example #2

//

Example #3

// 

Example #4

let name: String //

Example #5

let name: String // 

Triggering Examples (violation is marked with '↓'):

Example #1

let name: String 

Example #2

/* */ let name: String 

Mark (mark)

MARK comment should be in valid format.

Non-triggering Examples:

Example #1

// MARK: good

Example #2

// MARK: - good

Example #3

// MARK: -

Triggering Examples (violation is marked with '↓'):

Example #1

↓//MARK: bad

Example #2

↓// MARK:bad

Example #3

↓//MARK:bad

Example #4

↓//  MARK: bad

Example #5

↓// MARK:  bad

Example #6

↓// MARK: -bad

Example #7

↓// MARK:- bad

Example #8

↓// MARK:-bad

Example #9

↓//MARK: - bad

Example #10

↓//MARK:- bad

Example #11

↓//MARK: -bad

Example #12

↓//MARK:-bad

Empty Parameters (empty_parameters)

Prefer () -> over Void -> .

Non-triggering Examples:

Example #1

let abc: () -> Void = {}

Example #2

func foo(completion: () -> Void)

Example #3

func foo(completion: () thows -> Void)

Example #4

let foo: (ConfigurationTests) -> Void throws -> Void)

Example #5

let foo: (ConfigurationTests) ->   Void throws -> Void)

Example #6

let foo: (ConfigurationTests) ->Void throws -> Void)

Triggering Examples (violation is marked with '↓'):

Example #1

let abc: Void -> Void = {}

Example #2

func foo(completion: Void -> Void)

Example #3

func foo(completion: Void throws -> Void)

Example #4

let foo: Void -> () throws -> Void)

Legacy NSGeometry Functions (legacy_nsgeometry_functions)

Struct extension properties and methods are preferred over legacy functions

Non-triggering Examples:

Example #1

rect.width

Example #2

rect.height

Example #3

rect.minX

Example #4

rect.midX

Example #5

rect.maxX

Example #6

rect.minY

Example #7

rect.midY

Example #8

rect.maxY

Example #9

rect.isEmpty

Example #10

rect.integral

Example #11

rect.insetBy(dx: 5.0, dy: -7.0)

Example #12

rect.offsetBy(dx: 5.0, dy: -7.0)

Example #13

rect1.union(rect2)

Example #14

rect1.intersect(rect2)

Example #15

rect1.contains(rect2)

Example #16

rect.contains(point)

Example #17

rect1.intersects(rect2)

Triggering Examples (violation is marked with '↓'):

Example #1

NSWidth(rect)

Example #2

NSHeight(rect)

Example #3

NSMinX(rect)

Example #4

NSMidX(rect)

Example #5

NSMaxX(rect)

Example #6

NSMinY(rect)

Example #7

NSMidY(rect)

Example #8

NSMaxY(rect)

Example #9

NSEqualRects(rect1, rect2)

Example #10

NSEqualSizes(size1, size2)

Example #11

NSEqualPoints(point1, point2)

Example #12

NSEdgeInsetsEqual(insets2, insets2)

Example #13

NSIsEmptyRect(rect)

Example #14

NSIntegralRect(rect)

Example #15

NSInsetRect(rect, 10, 5)

Example #16

NSOffsetRect(rect, -2, 8.3)

Example #17

NSUnionRect(rect1, rect2)

Example #18

NSIntersectionRect(rect1, rect2)

Example #19

NSContainsRect(rect1, rect2)

Example #20

NSPointInRect(rect, point)

Example #21

NSIntersectsRect(rect1, rect2)

Implicitly Unwrapped Optional (implicitly_unwrapped_optional)

Implicitly unwrapped optionals should be avoided when possible.

Non-triggering Examples:

Example #1

@IBOutlet private var label: UILabel!

Example #2

@IBOutlet var label: UILabel!

Example #3

@IBOutlet var label: [UILabel!]

Example #4

if !boolean {}

Example #5

let int: Int? = 42

Example #6

let int: Int? = nil

Triggering Examples (violation is marked with '↓'):

Example #1

let label: UILabel!

Example #2

let IBOutlet: UILabel!

Example #3

let labels: [UILabel!]

Example #4

var ints: [Int!] = [42, nil, 42]

Example #5

let label: IBOutlet!

Example #6

let int: Int! = 42

Example #7

let int: Int! = nil

Example #8

var int: Int! = 42

Example #9

let int: ImplicitlyUnwrappedOptional<Int>

Example #10

let collection: AnyCollection<Int!>

Example #11

func foo(int: Int!) {}

Closing Brace Spacing (closing_brace)

Closing brace with closing parenthesis should not have any whitespaces in the middle.

Non-triggering Examples:

Example #1

[].map({ })

Example #2

[].map(
  { }
)

Triggering Examples (violation is marked with '↓'):

Example #1

[].map({ } )

Example #2

[].map({ }	)

Notification Center Detachment (notification_center_detachment)

An object should only remove itself as an observer in deinit.

Non-triggering Examples:

Example #1

class Foo { 
   deinit {
       NotificationCenter.default.removeObserver(self)
   }
}

Example #2

class Foo { 
   func bar() {
       NotificationCenter.default.removeObserver(otherObject)
   }
}

Triggering Examples (violation is marked with '↓'):

Example #1

class Foo { 
   func bar() {
       NotificationCenter.default.removeObserver(self)
   }
}

Class Delegate Protocol (class_delegate_protocol)

Delegate protocols should be class-only so they can be weakly referenced.

Non-triggering Examples:

Example #1

protocol FooDelegate: class {}

Example #2

protocol FooDelegate: class, BarDelegate {}

Example #3

protocol Foo {}

Example #4

class FooDelegate {}

Example #5

@objc protocol FooDelegate {}

Example #6

@objc(MyFooDelegate)
 protocol FooDelegate {}

Example #7

protocol FooDelegate: BarDelegate {}

Example #8

protocol FooDelegate: AnyObject {}

Example #9

protocol FooDelegate: NSObjectProtocol {}

Triggering Examples (violation is marked with '↓'):

Example #1

protocol FooDelegate {}

Example #2

protocol FooDelegate: Bar {}

Colon (colon)

Colons should be next to the identifier when specifying a type and next to the key in dictionary literals.

Non-triggering Examples:

Example #1

let abc: Void

Example #2

let abc: [Void: Void]

Example #3

let abc: (Void, Void)

Example #4

let abc: ([Void], String, Int)

Example #5

let abc: [([Void], String, Int)]

Example #6

let abc: String="def"

Example #7

let abc: Int=0

Example #8

let abc: Enum=Enum.Value

Example #9

func abc(def: Void) {}

Example #10

func abc(def: Void, ghi: Void) {}

Example #11

// 周斌佳年周斌佳
let abc: String = "abc:"

Example #12

let abc = [Void: Void]()

Example #13

let abc = [1: [3: 2], 3: 4]

Example #14

let abc = ["string": "string"]

Example #15

let abc = ["string:string": "string"]

Triggering Examples (violation is marked with '↓'):

Example #1

let abc:Void

Example #2

let abc:  Void

Example #3

let abc :Void

Example #4

let abc : Void

Example #5

let abc : [Void: Void]

Example #6

let abc : (Void, String, Int)

Example #7

let abc : ([Void], String, Int)

Example #8

let abc : [([Void], String, Int)]

Example #9

let abc:  (Void, String, Int)

Example #10

let abc:  ([Void], String, Int)

Example #11

let abc:  [([Void], String, Int)]

Example #12

let abc :String="def"

Example #13

let abc :Int=0

Example #14

let abc :Int = 0

Example #15

let abc:Int=0

Example #16

let abc:Int = 0

Example #17

let abc:Enum=Enum.Value

Example #18

func abc(def:Void) {}

Example #19

func abc(def:  Void) {}

Example #20

func abc(def :Void) {}

Example #21

func abc(def : Void) {}

Example #22

func abc(def: Void, ghi :Void) {}

Example #23

let abc = [Void:Void]()

Example #24

let abc = [Void : Void]()

Example #25

let abc = [Void:  Void]()

Example #26

let abc = [Void :  Void]()

Example #27

let abc = [1: [3 : 2], 3: 4]

Example #28

let abc = [1: [3 : 2], 3:  4]

Shorthand Operator (shorthand_operator)

Prefer shorthand operators (+=, -=, *=, /=) over doing the operation and assigning.

Non-triggering Examples:

Example #1

foo -= 1

Example #2

foo -= variable

Example #3

foo -= bar.method()

Example #4

self.foo = foo - 1

Example #5

foo = self.foo - 1

Example #6

page = ceilf(currentOffset - pageWidth)

Example #7

foo = aMethod(foo - bar)

Example #8

foo = aMethod(bar - foo)

Example #9

foo /= 1

Example #10

foo /= variable

Example #11

foo /= bar.method()

Example #12

self.foo = foo / 1

Example #13

foo = self.foo / 1

Example #14

page = ceilf(currentOffset / pageWidth)

Example #15

foo = aMethod(foo / bar)

Example #16

foo = aMethod(bar / foo)

Example #17

foo += 1

Example #18

foo += variable

Example #19

foo += bar.method()

Example #20

self.foo = foo + 1

Example #21

foo = self.foo + 1

Example #22

page = ceilf(currentOffset + pageWidth)

Example #23

foo = aMethod(foo + bar)

Example #24

foo = aMethod(bar + foo)

Example #25

foo *= 1

Example #26

foo *= variable

Example #27

foo *= bar.method()

Example #28

self.foo = foo * 1

Example #29

foo = self.foo * 1

Example #30

page = ceilf(currentOffset * pageWidth)

Example #31

foo = aMethod(foo * bar)

Example #32

foo = aMethod(bar * foo)

Example #33

var helloWorld = "world!"
 helloWorld = "Hello, " + helloWorld

Example #34

angle = someCheck ? angle : -angle

Triggering Examples (violation is marked with '↓'):

Example #1

foo = foo - 1

Example #2

foo = foo - aVariable

Example #3

foo = foo - bar.method()

Example #4

foo.aProperty = foo.aProperty - 1

Example #5

self.aProperty = self.aProperty - 1

Example #6

foo = foo / 1

Example #7

foo = foo / aVariable

Example #8

foo = foo / bar.method()

Example #9

foo.aProperty = foo.aProperty / 1

Example #10

self.aProperty = self.aProperty / 1

Example #11

foo = foo + 1

Example #12

foo = foo + aVariable

Example #13

foo = foo + bar.method()

Example #14

foo.aProperty = foo.aProperty + 1

Example #15

self.aProperty = self.aProperty + 1

Example #16

foo = foo * 1

Example #17

foo = foo * aVariable

Example #18

foo = foo * bar.method()

Example #19

foo.aProperty = foo.aProperty * 1

Example #20

self.aProperty = self.aProperty * 1

Closure Parameter Position (closure_parameter_position)

Closure parameters should be on the same line as opening brace.

Non-triggering Examples:

Example #1

[1, 2].map { $0 + 1 }

Example #2

[1, 2].map({ $0 + 1 })

Example #3

[1, 2].map { number in
 number + 1 
}

Example #4

[1, 2].map { number -> Int in
 number + 1 
}

Example #5

[1, 2].map { (number: Int) -> Int in
 number + 1 
}

Example #6

[1, 2].map { [weak self] number in
 number + 1 
}

Example #7

[1, 2].something(closure: { number in
 number + 1 
})

Example #8

let isEmpty = [1, 2].isEmpty()

Example #9

rlmConfiguration.migrationBlock.map { rlmMigration in
return { migration, schemaVersion in
rlmMigration(migration.rlmMigration, schemaVersion)
}
}

Example #10

let mediaView: UIView = { [weak self] index in
   return UIView()
}(index)

Triggering Examples (violation is marked with '↓'):

Example #1

[1, 2].map {
 number in
 number + 1 
}

Example #2

[1, 2].map {
 number -> Int in
 number + 1 
}

Example #3

[1, 2].map {
 (number: Int) -> Int in
 number + 1 
}

Example #4

[1, 2].map {
 [weak self] ↓number in
 number + 1 
}

Example #5

[1, 2].map { [weak self]
 ↓number in
 number + 1 
}

Example #6

[1, 2].map({
 number in
 number + 1 
})

Example #7

[1, 2].something(closure: {
 number in
 number + 1 
})

Example #8

[1, 2].reduce(0) {
 sum, number in
 number + sum 
}

Nesting (nesting)

Types should be nested at most 1 level deep, and statements should be nested at most 5 levels deep.

Non-triggering Examples:

Example #1

class Class0 { class Class1 {} }

Example #2

func func0() {
func func1() {
func func2() {
func func3() {
func func4() { func func5() {
}
}
}
}
}
}

Example #3

struct Class0 { struct Class1 {} }

Example #4

func func0() {
func func1() {
func func2() {
func func3() {
func func4() { func func5() {
}
}
}
}
}
}

Example #5

enum Class0 { enum Class1 {} }

Example #6

func func0() {
func func1() {
func func2() {
func func3() {
func func4() { func func5() {
}
}
}
}
}
}

Example #7

enum Enum0 { enum Enum1 { case Case } }

Triggering Examples (violation is marked with '↓'):

Example #1

class A { class B { class C {} } }

Example #2

struct A { struct B { struct C {} } }

Example #3

enum A { enum B { enum C {} } }

Example #4

func func0() {
func func1() {
func func2() {
func func3() {
func func4() { func func5() {
func func6() {
}
}
}
}
}
}
}

Switch Case on Newline (switch_case_on_newline)

Cases inside a switch should always be on a newline

Non-triggering Examples:

Example #1

/*case 1: */return true

Example #2

//case 1:
 return true

Example #3

let x = [caseKey: value]

Example #4

let x = [key: .default]

Example #5

if case let .someEnum(value) = aFunction([key: 2]) { }

Example #6

guard case let .someEnum(value) = aFunction([key: 2]) { }

Example #7

for case let .someEnum(value) = aFunction([key: 2]) { }

Example #8

enum Environment {
 case development
}

Example #9

enum Environment {
 case development(url: URL)
}

Example #10

enum Environment {
 case development(url: URL) // staging
}

Example #11

switch foo {
  case 1:
 return true
}

Example #12

switch foo {
  default:
 return true
}

Example #13

switch foo {
  case let value:
 return true
}

Example #14

switch foo {
  case .myCase: // error from network
 return true
}

Example #15

switch foo {
  case let .myCase(value) where value > 10:
 return false
}

Example #16

switch foo {
  case let .myCase(value)
 where value > 10:
 return false
}

Example #17

switch foo {
  case let .myCase(code: lhsErrorCode, description: _)
 where lhsErrorCode > 10:
 return false
}

Example #18

switch foo {
  case #selector(aFunction(_:)):
 return false

}

Triggering Examples (violation is marked with '↓'):

Example #1

switch foo {
  case 1: return true
}

Example #2

switch foo {
  case let value: return true
}

Example #3

switch foo {
  default: return true
}

Example #4

switch foo {
  case "a string": return false
}

Example #5

switch foo {
  case .myCase: return false // error from network
}

Example #6

switch foo {
  case let .myCase(value) where value > 10: return false
}

Example #7

switch foo {
  case #selector(aFunction(_:)): return false

}

Example #8

switch foo {
  case let .myCase(value)
 where value > 10: return false
}

Example #9

switch foo {
  case .first,
 .second: return false
}

File Header (file_header)

Files should have consistent header comments.

Non-triggering Examples:

Example #1

let foo = "Copyright"

Example #2

let foo = 2 // Copyright

Example #3

let foo = 2
 // Copyright

Triggering Examples (violation is marked with '↓'):

Example #1

// ↓Copyright

Example #2

//
// ↓Copyright

Example #3

//
//  FileHeaderRule.swift
//  SwiftLint
//
//  Created by Marcelo Fabri on 27/11/16.
//  ↓Copyright © 2016 Realm. All rights reserved.
//

Conditional Returns on Newline (conditional_returns_on_newline)

Conditional statements should always return on the next line

Non-triggering Examples:

Example #1

guard true else {
 return true
}

Example #2

guard true,
 let x = true else {
 return true
}

Example #3

if true else {
 return true
}

Example #4

if true,
 let x = true else {
 return true
}

Example #5

if textField.returnKeyType == .Next {

Example #6

if true { // return }

Example #7

/*if true { */ return }

Triggering Examples (violation is marked with '↓'):

Example #1

guard true else { return }

Example #2

if true { return }

Example #3

if true { break } else { return }

Example #4

if true { break } else {       return }

Example #5

if true { return "YES" } else { return "NO" }

Trailing Newline (trailing_newline)

Files should have a single trailing newline.

Non-triggering Examples:

Example #1

let a = 0

Triggering Examples (violation is marked with '↓'):

Example #1

let a = 0

Example #2

let a = 0

Missing Docs (missing_docs)

Public declarations should be documented.

Non-triggering Examples:

Example #1

/// docs
public func a() {}

Example #2

/** docs */
public func a() {}

Example #3

func a() {}

Example #4

internal func a() {}

Example #5

private func a() {}

Example #6

// regular comment
func a() {}

Example #7

/* regular comment */
func a() {}

Example #8

/// docs
public protocol A {
/// docs
var b: Int { get } }
/// docs
public struct C: A {
public let b: Int
}

Example #9

/// docs
public class A {
/// docs
public func b() {}
}
/// docs
public class B: A { override public func b() {} }

Example #10

import Foundation
/// docs
public class B: NSObject {
// no docs
override public var description: String { fatalError() } }

Triggering Examples (violation is marked with '↓'):

Example #1

public func a() {}

Example #2

// regular comment
public func a() {}

Example #3

/* regular comment */
public func a() {}

Example #4

/// docs
public protocol A {
// no docs
var b: Int { get } }
/// docs
public struct C: A {

public let b: Int
}

For Where (for_where)

where clauses are preferred over a single if inside a for.

Non-triggering Examples:

Example #1

for user in users where user.id == 1 { }

Example #2

for user in users {
   if let id = user.id { }
}

Example #3

for user in users {
   if user.id == 1 { } else { }
}

Example #4

for user in users {
   if user.id == 1 {
} else if user.id == 2 { }
}

Example #5

for user in users {
   if user.id == 1 { }
   print(user)
}

Example #6

for user in users {
   let id = user.id
   if id == 1 { }
}

Example #7

for user in users {
   if user.id == 1 { }
   return true
}

Example #8

for user in users {
   if user.id == 1 && user.age > 18 { }
}

Triggering Examples (violation is marked with '↓'):

Example #1

for user in users {
   if user.id == 1 { return true }
}

Redundant Nil Coalescing (redundant_nil_coalescing)

nil coalescing operator is only evaluated if the lhs is nil, coalescing operator with nil as rhs is redundant

Non-triggering Examples:

Example #1

var myVar: Int?; myVar ?? 0

Triggering Examples (violation is marked with '↓'):

Example #1

var myVar: Int? = nil; myVar ?? nil

Example #2

var myVar: Int? = nil; myVar↓??nil

Private Unit Test (private_unit_test)

Unit tests marked private are silently skipped.

Non-triggering Examples:

Example #1

class FooTest: XCTestCase { func test1() {}
 internal func test2() {}
 public func test3() {}
 }

Example #2

internal class FooTest: XCTestCase { func test1() {}
 internal func test2() {}
 public func test3() {}
 }

Example #3

public class FooTest: XCTestCase { func test1() {}
 internal func test2() {}
 public func test3() {}
 }

Example #4

private class Foo: NSObject { func test1() {}
 internal func test2() {}
 public func test3() {}
 }

Example #5

private class Foo { func test1() {}
 internal func test2() {}
 public func test3() {}
 }

Triggering Examples (violation is marked with '↓'):

Example #1

private class FooTest: XCTestCase { func test1() {}
 internal func test2() {}
 public func test3() {}
 private func test4() {}
 }

Example #2

class FooTest: XCTestCase { func test1() {}
 internal func test2() {}
 public func test3() {}
 privatefunc test4() {}
 }

Example #3

internal class FooTest: XCTestCase { func test1() {}
 internal func test2() {}
 public func test3() {}
 privatefunc test4() {}
 }

Example #4

public class FooTest: XCTestCase { func test1() {}
 internal func test2() {}
 public func test3() {}
 privatefunc test4() {}
 }

Compiler Protocol Init (compiler_protocol_init)

The initializers declared in compiler protocols such as ExpressibleByArrayLiteral shouldn't be called directly.

Non-triggering Examples:

Example #1

let set: Set<Int> = [1, 2]

Example #2

let set = Set(array)

Triggering Examples (violation is marked with '↓'):

Example #1

let set = Set(arrayLiteral: 1, 2)

Example #2

let set = Set.init(arrayLiteral: 1, 2)

Returning Whitespace (return_arrow_whitespace)

Return arrow and return type should be separated by a single space or on a separate line.

Non-triggering Examples:

Example #1

func abc() -> Int {}

Example #2

func abc() -> [Int] {}

Example #3

func abc() -> (Int, Int) {}

Example #4

var abc = {(param: Int) -> Void in }

Example #5

func abc() ->
    Int {}

Example #6

func abc()
    -> Int {}

Triggering Examples (violation is marked with '↓'):

Example #1

func abc()↓->Int {}

Example #2

func abc()↓->[Int] {}

Example #3

func abc()↓->(Int, Int) {}

Example #4

func abc()↓-> Int {}

Example #5

func abc() ->Int {}

Example #6

func abc()  ->  Int {}

Example #7

var abc = {(param: Int) ->Bool in }

Example #8

var abc = {(param: Int)↓->Bool in }

Operator Usage Whitespace (operator_usage_whitespace)

Operators should be surrounded by a single whitespace when they are being used.

Non-triggering Examples:

Example #1

let foo = 1 + 2

Example #2

let foo = 1 > 2

Example #3

let foo = !false

Example #4

let foo: Int?

Example #5

let foo: Array<String>

Example #6

let foo: [String]

Example #7

let foo = 1 + 
  2

Example #8

let range = 1...3

Example #9

let range = 1 ... 3

Example #10

let range = 1..<3

Example #11

#if swift(>=3.0)

Example #12

array.removeAtIndex(-200)

Example #13

let name = "image-1"

Example #14

button.setImage(#imageLiteral(resourceName: "image-1"), for: .normal)

Example #15

let doubleValue = -9e-11

Triggering Examples (violation is marked with '↓'):

Example #1

let foo = 1↓+2

Example #2

let foo = 1   + 2

Example #3

let foo = 1   +    2

Example #4

let foo = 1 +    2

Example #5

let foo↓=1↓+2

Example #6

let foo↓=1 + 2

Example #7

let foo↓=bar

Example #8

let range = 1 ..<  3

Example #9

let foo = bar   ?? 0

Example #10

let foo = bar↓??0

Example #11

let foo = bar !=  0

Example #12

let foo = bar !==  bar2

Example #13

let v8 = Int8(1)  << 6

Example #14

let v8 = 1 <<  (6)

Example #15

let v8 = 1 <<  (6)
 let foo = 1 > 2

Attributes (attributes)

Attributes should be on their own lines in functions and types, but on the same line as variables and imports.

Non-triggering Examples:

Example #1

@objc var x: String

Example #2

@objc private var x: String

Example #3

@nonobjc var x: String

Example #4

@IBOutlet private var label: UILabel

Example #5

@IBOutlet @objc private var label: UILabel

Example #6

@NSCopying var name: NSString

Example #7

@NSManaged var name: String?

Example #8

@IBInspectable var cornerRadius: CGFloat

Example #9

@available(iOS 9.0, *)
 let stackView: UIStackView

Example #10

@NSManaged func addSomeObject(book: SomeObject)

Example #11

@IBAction func buttonPressed(button: UIButton)

Example #12

@objc
 @IBAction func buttonPressed(button: UIButton)

Example #13

@available(iOS 9.0, *)
 func animate(view: UIStackView)

Example #14

@available(iOS 9.0, *, message="A message")
 func animate(view: UIStackView)

Example #15

@nonobjc
 final class X

Example #16

@available(iOS 9.0, *)
 class UIStackView

Example #17

@NSApplicationMain
 class AppDelegate: NSObject, NSApplicationDelegate

Example #18

@UIApplicationMain
 class AppDelegate: NSObject, UIApplicationDelegate

Example #19

@IBDesignable
 class MyCustomView: UIView

Example #20

@testable import SourceKittenFramework

Example #21

@objc(foo_x)
 var x: String

Example #22

@available(iOS 9.0, *)
@objc(abc_stackView)
 let stackView: UIStackView

Example #23

@objc(abc_addSomeObject:)
 @NSManaged func addSomeObject(book: SomeObject)

Example #24

@objc(ABCThing)
 @available(iOS 9.0, *)
 class Thing

Example #25

class Foo: NSObject {
 override var description: String { return "" }
}

Example #26

class Foo: NSObject {

 override func setUp() {}
}

Example #27

@objc
class{}

Example #28

extension Property {

 @available(*, unavailable, renamed: "isOptional")
public var optional: Bool { fatalError() }
}

Example #29

@GKInspectable var maxSpeed: Float

Example #30

@discardableResult
 func a() -> Int

Example #31

@objc
 @discardableResult
 func a() -> Int

Example #32

func increase(f: @autoclosure () -> Int) -> Int

Example #33

func foo(completionHandler: @escaping () -> Void)

Triggering Examples (violation is marked with '↓'):

Example #1

@objc
 var x: String

Example #2

@objc

 var x: String

Example #3

@objc
 private var x: String

Example #4

@nonobjc
 var x: String

Example #5

@IBOutlet
 private var label: UILabel

Example #6

@IBOutlet

 private var label: UILabel

Example #7

@NSCopying
 var name: NSString

Example #8

@NSManaged
 var name: String?

Example #9

@IBInspectable
 var cornerRadius: CGFloat

Example #10

@available(iOS 9.0, *) let stackView: UIStackView

Example #11

@NSManaged
 func addSomeObject(book: SomeObject)

Example #12

@IBAction
 func buttonPressed(button: UIButton)

Example #13

@IBAction
 @objc
 func buttonPressed(button: UIButton)

Example #14

@available(iOS 9.0, *) func animate(view: UIStackView)

Example #15

@nonobjc final class X

Example #16

@available(iOS 9.0, *) class UIStackView

Example #17

@available(iOS 9.0, *)
 @objc class UIStackView

Example #18

@available(iOS 9.0, *) @objc
 class UIStackView

Example #19

@available(iOS 9.0, *)

 class UIStackView

Example #20

@UIApplicationMain class AppDelegate: NSObject, UIApplicationDelegate

Example #21

@IBDesignable class MyCustomView: UIView

Example #22

@testable
import SourceKittenFramework

Example #23

@testable


import SourceKittenFramework

Example #24

@objc(foo_x) var x: String

Example #25

@available(iOS 9.0, *) @objc(abc_stackView)
 let stackView: UIStackView

Example #26

@objc(abc_addSomeObject:) @NSManaged
 func addSomeObject(book: SomeObject)

Example #27

@objc(abc_addSomeObject:)
 @NSManaged
 func addSomeObject(book: SomeObject)

Example #28

@available(iOS 9.0, *)
 @objc(ABCThing) class Thing

Example #29

@GKInspectable
 var maxSpeed: Float

Example #30

@discardableResult func a() -> Int

Example #31

@objc
 @discardableResult func a() -> Int

Example #32

@objc

 @discardableResult
 func a() -> Int

Overridden methods call super (overridden_super_call)

Some overridden methods should always call super

Non-triggering Examples:

Example #1

class VC: UIViewController {
	override func viewWillAppear(_ animated: Bool) {
		super.viewWillAppear(animated)
	}
}

Example #2

class VC: UIViewController {
	override func viewWillAppear(_ animated: Bool) {
		self.method1()
		super.viewWillAppear(animated)
		self.method2()
	}
}

Example #3

class VC: UIViewController {
	override func loadView() {
	}
}

Example #4

class Some {
	func viewWillAppear(_ animated: Bool) {
	}
}

Triggering Examples (violation is marked with '↓'):

Example #1

class VC: UIViewController {
	override func viewWillAppear(_ animated: Bool) {
		//Not calling to super
		self.method()
	}
}

Example #2

class VC: UIViewController {
	override func viewWillAppear(_ animated: Bool) {
		super.viewWillAppear(animated)
		//Other code
		super.viewWillAppear(animated)
	}
}

Example #3

class VC: UIViewController {
	override func didReceiveMemoryWarning() {
	}
}

Fatal Errror Message (fatal_error_message)

A fatalError call should have a message.

Non-triggering Examples:

Example #1

func foo() {
  fatalError("Foo")
}

Example #2

func foo() {
  fatalError(x)
}

Triggering Examples (violation is marked with '↓'):

Example #1

func foo() {
  fatalError("")
}

Example #2

func foo() {
  fatalError()
}

Vertical Parameter Alignment (vertical_parameter_alignment)

Function parameters should be aligned vertically if they're in multiple lines in a declaration.

Non-triggering Examples:

Example #1

func validateFunction(_ file: File, kind: SwiftDeclarationKind,
                      dictionary: [String: SourceKitRepresentable]) { }

Example #2

func validateFunction(_ file: File, kind: SwiftDeclarationKind,
                      dictionary: [String: SourceKitRepresentable]) -> [StyleViolation]

Example #3

func foo(bar: Int)

Example #4

func foo(bar: Int) -> String 

Example #5

func validateFunction(_ file: File, kind: SwiftDeclarationKind,
                      dictionary: [String: SourceKitRepresentable])
                      -> [StyleViolation]

Example #6

func validateFunction(
   _ file: File, kind: SwiftDeclarationKind,
   dictionary: [String: SourceKitRepresentable]) -> [StyleViolation]

Example #7

func validateFunction(
   _ file: File, kind: SwiftDeclarationKind,
   dictionary: [String: SourceKitRepresentable]
) -> [StyleViolation]

Example #8

func regex(_ pattern: String,
           options: NSRegularExpression.Options = [.anchorsMatchLines,
                                                   .dotMatchesLineSeparators]) -> NSRegularExpression

Triggering Examples (violation is marked with '↓'):

Example #1

func validateFunction(_ file: File, kind: SwiftDeclarationKind,
                  dictionary: [String: SourceKitRepresentable]) { }

Example #2

func validateFunction(_ file: File, kind: SwiftDeclarationKind,
                       dictionary: [String: SourceKitRepresentable]) { }

Example #3

func validateFunction(_ file: File,
                  kind: SwiftDeclarationKind,
                  dictionary: [String: SourceKitRepresentable]) { }

First Where (first_where)

Prefer using .first(where:) over .filter { }.first in collections.

Non-triggering Examples:

Example #1

kinds.filter(excludingKinds.contains).isEmpty && kinds.first == .identifier

Example #2

myList.first(where: { $0 % 2 == 0 })

Example #3

match(pattern: pattern).filter { $0.first == .identifier }

Triggering Examples (violation is marked with '↓'):

Example #1

myList.filter { $0 % 2 == 0 }.first

Example #2

myList.filter({ $0 % 2 == 0 }).first

Example #3

myList.map { $0 + 1 }.filter({ $0 % 2 == 0 }).first

Example #4

myList.map { $0 + 1 }.filter({ $0 % 2 == 0 }).first?.something()

Example #5

myList.filter(someFunction).first

Example #6

myList.filter({ $0 % 2 == 0 })
.first

Private Outlets (private_outlet)

IBOutlets should be private to avoid leaking UIKit to higher layers.

Non-triggering Examples:

Example #1

class Foo {
  @IBOutlet private var label: UILabel?
}

Example #2

class Foo {
  @IBOutlet private var label: UILabel!
}

Example #3

class Foo {
  var notAnOutlet: UILabel
}

Example #4

class Foo {
  @IBOutlet weak private var label: UILabel?
}

Example #5

class Foo {
  @IBOutlet private weak var label: UILabel?
}

Triggering Examples (violation is marked with '↓'):

Example #1

class Foo {
  @IBOutlet var label: UILabel?
}

Example #2

class Foo {
  @IBOutlet var label: UILabel!
}

Generic Type Name (generic_type_name)

Generic type name should only contain alphanumeric characters, start with an uppercase character and span between 1 and 20 characters in length.

Non-triggering Examples:

Example #1

func foo<T>() {}

Example #2

func foo<T>() -> T {}

Example #3

func foo<T, U>(param: U) -> T {}

Example #4

func foo<T: Hashable, U: Rule>(param: U) -> T {}

Example #5

struct Foo<T> {}

Example #6

class Foo<T> {}

Example #7

enum Foo<T> {}

Example #8

func run(_ options: NoOptions<CommandantError<()>>) {}

Example #9

func foo(_ options: Set<type>) {}

Example #10

func < <T: Comparable>(lhs: T?, rhs: T?) -> Bool

Example #11

func configureWith(data: Either<MessageThread, (project: Project, backing: Backing)>)

Example #12

typealias StringDictionary<T> = Dictionary<String, T>

Example #13

typealias BackwardTriple<T1, T2, T3> = (T3, T2, T1)

Example #14

typealias DictionaryOfStrings<T : Hashable> = Dictionary<T, String>

Triggering Examples (violation is marked with '↓'):

Example #1

func foo<T_Foo>() {}

Example #2

func foo<T, U_Foo>(param: U_Foo) -> T {}

Example #3

func foo<TTTTTTTTTTTTTTTTTTTTT>() {}

Example #4

func foo<type>() {}

Example #5

typealias StringDictionary<T_Foo> = Dictionary<String, T_Foo>

Example #6

typealias BackwardTriple<T1, T2_Bar, T3> = (T3, T2_Bar, T1)

Example #7

typealias DictionaryOfStrings<T_Foo: Hashable> = Dictionary<T, String>

Example #8

class Foo<T_Foo> {}

Example #9

class Foo<T, U_Foo> {}

Example #10

class Foo<T_Foo, U_Foo> {}

Example #11

class Foo<TTTTTTTTTTTTTTTTTTTTT> {}

Example #12

class Foo<type> {}

Example #13

struct Foo<T_Foo> {}

Example #14

struct Foo<T, U_Foo> {}

Example #15

struct Foo<T_Foo, U_Foo> {}

Example #16

struct Foo<TTTTTTTTTTTTTTTTTTTTT> {}

Example #17

struct Foo<type> {}

Example #18

enum Foo<T_Foo> {}

Example #19

enum Foo<T, U_Foo> {}

Example #20

enum Foo<T_Foo, U_Foo> {}

Example #21

enum Foo<TTTTTTTTTTTTTTTTTTTTT> {}

Example #22

enum Foo<type> {}

Explicit Init (explicit_init)

Explicitly calling .init() should be avoided.

Non-triggering Examples:

Example #1

import Foundation; class C: NSObject { override init() { super.init() }}

Example #2

struct S { let n: Int }; extension S { init() { self.init(n: 1) } }

Example #3

[1].flatMap(String.init)

Example #4

[String.self].map { $0.init(1) }

Example #5

[String.self].map { type in type.init(1) }

Triggering Examples (violation is marked with '↓'):

Example #1

[1].flatMap{String.init($0)}

Example #2

[String.self].map { Type in Type.init(1) }

Legacy Constructor (legacy_constructor)

Swift constructors are preferred over legacy convenience functions.

Non-triggering Examples:

Example #1

CGPoint(x: 10, y: 10)

Example #2

CGPoint(x: xValue, y: yValue)

Example #3

CGSize(width: 10, height: 10)

Example #4

CGSize(width: aWidth, height: aHeight)

Example #5

CGRect(x: 0, y: 0, width: 10, height: 10)

Example #6

CGRect(x: xVal, y: yVal, width: aWidth, height: aHeight)

Example #7

CGVector(dx: 10, dy: 10)

Example #8

CGVector(dx: deltaX, dy: deltaY)

Example #9

NSPoint(x: 10, y: 10)

Example #10

NSPoint(x: xValue, y: yValue)

Example #11

NSSize(width: 10, height: 10)

Example #12

NSSize(width: aWidth, height: aHeight)

Example #13

NSRect(x: 0, y: 0, width: 10, height: 10)

Example #14

NSRect(x: xVal, y: yVal, width: aWidth, height: aHeight)

Example #15

NSRange(location: 10, length: 1)

Example #16

NSRange(location: loc, length: len)

Example #17

UIEdgeInsets(top: 0, left: 0, bottom: 10, right: 10)

Example #18

UIEdgeInsets(top: aTop, left: aLeft, bottom: aBottom, right: aRight)

Example #19

NSEdgeInsets(top: 0, left: 0, bottom: 10, right: 10)

Example #20

NSEdgeInsets(top: aTop, left: aLeft, bottom: aBottom, right: aRight)

Triggering Examples (violation is marked with '↓'):

Example #1

CGPointMake(10, 10)

Example #2

CGPointMake(xVal, yVal)

Example #3

CGSizeMake(10, 10)

Example #4

CGSizeMake(aWidth, aHeight)

Example #5

CGRectMake(0, 0, 10, 10)

Example #6

CGRectMake(xVal, yVal, width, height)

Example #7

CGVectorMake(10, 10)

Example #8

CGVectorMake(deltaX, deltaY)

Example #9

NSMakePoint(10, 10)

Example #10

NSMakePoint(xVal, yVal)

Example #11

NSMakeSize(10, 10)

Example #12

NSMakeSize(aWidth, aHeight)

Example #13

NSMakeRect(0, 0, 10, 10)

Example #14

NSMakeRect(xVal, yVal, width, height)

Example #15

NSMakeRange(10, 1)

Example #16

NSMakeRange(loc, len)

Example #17

UIEdgeInsetsMake(0, 0, 10, 10)

Example #18

UIEdgeInsetsMake(top, left, bottom, right)

Example #19

NSEdgeInsetsMake(0, 0, 10, 10)

Example #20

NSEdgeInsetsMake(top, left, bottom, right)

Discarded Notification Center Observer (discarded_notification_center_observer)

When registing for a notification using a block, the opaque observer that is returned should be stored so it can be removed later.

Non-triggering Examples:

Example #1

let foo = nc.addObserver(forName: .NSSystemTimeZoneDidChange, object: nil, queue: nil) { }

Example #2

let foo = nc.addObserver(forName: .NSSystemTimeZoneDidChange, object: nil, queue: nil, using: { })

Triggering Examples (violation is marked with '↓'):

Example #1

nc.addObserver(forName: .NSSystemTimeZoneDidChange, object: nil, queue: nil) { }

Example #2

nc.addObserver(forName: .NSSystemTimeZoneDidChange, object: nil, queue: nil, using: { })

Closure End Indentation (closure_end_indentation)

Closure end should have the same indentation as the line that started it.

Non-triggering Examples:

Example #1

SignalProducer(values: [1, 2, 3])
   .startWithNext { number in
       print(number)
   }

Example #2

[1, 2].map { $0 + 1 }

Example #3

return match(pattern: pattern, with: [.comment]).flatMap { range in
   return Command(string: contents, range: range)
}.flatMap { command in
   return command.expand()
}

Example #4

foo(foo: bar,
    options: baz) { _ in }

Example #5

someReallyLongProperty.chainingWithAnotherProperty
   .foo { _ in }

Example #6

foo(abc, 123)
{ _ in }

Triggering Examples (violation is marked with '↓'):

Example #1

SignalProducer(values: [1, 2, 3])
   .startWithNext { number in
       print(number)
}

Example #2

return match(pattern: pattern, with: [.comment]).flatMap { range in
   return Command(string: contents, range: range)
   }.flatMap { command in
   return command.expand()
}

Identifier Name (identifier_name)

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.

Non-triggering Examples:

Example #1

let myLet = 0

Example #2

var myVar = 0

Example #3

private let _myLet = 0

Example #4

class Abc { static let MyLet = 0 }

Example #5

let URL: NSURL? = nil

Example #6

let XMLString: String? = nil

Example #7

override var i = 0

Example #8

enum Foo { case myEnum }

Example #9

func isOperator(name: String) -> Bool

Example #10

func typeForKind(_ kind: SwiftDeclarationKind) -> String

Example #11

func == (lhs: SyntaxToken, rhs: SyntaxToken) -> Bool

Example #12

override func IsOperator(name: String) -> Bool

Triggering Examples (violation is marked with '↓'):

Example #1

let MyLet = 0

Example #2

let _myLet = 0

Example #3

private let myLet_ = 0

Example #4

let myExtremelyVeryVeryVeryVeryVeryVeryLongLet = 0

Example #5

var myExtremelyVeryVeryVeryVeryVeryVeryLongVar = 0

Example #6

private let _myExtremelyVeryVeryVeryVeryVeryVeryLongLet = 0

Example #7

let i = 0

Example #8

var id = 0

Example #9

private let _i = 0

Example #10

func IsOperator(name: String) -> Bool

Example #11

enum Foo { case MyEnum }

Custom Rules (custom_rules)

Create custom rules by providing a regex string. Optionally specify what syntax kinds to match against, the severity level, and what message to display.

Non-triggering Examples:

Triggering Examples (violation is marked with '↓'):

Function Parameter Count (function_parameter_count)

Number of function parameters should be low.

Non-triggering Examples:

Example #1

init(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) {}

Example #2

init (a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) {}

Example #3

`init`(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) {}

Example #4

init?(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) {}

Example #5

init?<T>(a: T, b: Int, c: Int, d: Int, e: Int, f: Int) {}

Example #6

init?<T: String>(a: T, b: Int, c: Int, d: Int, e: Int, f: Int) {}

Example #7

func f2(p1: Int, p2: Int) { }

Example #8

func f(a: Int, b: Int, c: Int, d: Int, x: Int = 42) {}

Example #9

func f(a: [Int], b: Int, c: Int, d: Int, f: Int) -> [Int] {
let s = a.flatMap { $0 as? [String: Int] } ?? []}}

Triggering Examples (violation is marked with '↓'):

Example #1

func f(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) {}

Example #2

func initialValue(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) {}

Example #3

func f(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int = 2, g: Int) {}

Example #4

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) {}}

Syntactic Sugar (syntactic_sugar)

Shorthand syntactic sugar should be used, i.e. [Int] instead of Array

Non-triggering Examples:

Example #1

let x: [Int]

Example #2

let x: [Int: String]

Example #3

let x: Int?

Example #4

func x(a: [Int], b: Int) -> [Int: Any]

Example #5

let x: Int!

Example #6

extension Array { 
 func x() { } 
 }

Example #7

extension Dictionary { 
 func x() { } 
 }

Example #8

let x: CustomArray<String>

Example #9

var currentIndex: Array<OnboardingPage>.Index?

Example #10

func x(a: [Int], b: Int) -> Array<Int>.Index

Example #11

unsafeBitCast(nonOptionalT, to: Optional<T>.self)

Example #12

type is Optional<String>.Type

Triggering Examples (violation is marked with '↓'):

Example #1

let x: Array<String>

Example #2

let x: Dictionary<Int, String>

Example #3

let x: Optional<Int>

Example #4

let x: ImplicitlyUnwrappedOptional<Int>

Example #5

func x(a: Array<Int>, b: Int) -> [Int: Any]

Example #6

func x(a: [Int], b: Int) -> ↓Dictionary<Int, String>

Example #7

func x(a: Array<Int>, b: Int) -> Dictionary<Int, String>

Example #8

let x = Array<String>.array(of: object)

Trailing Comma (trailing_comma)

Trailing commas in arrays and dictionaries should be avoided/enforced.

Non-triggering Examples:

Example #1

let foo = [1, 2, 3]

Example #2

let foo = []

Example #3

let foo = [:]

Example #4

let foo = [1: 2, 2: 3]

Example #5

let foo = [Void]()

Example #6

let example = [ 1,
 2
 // 3,
]

Example #7

foo([1: "\(error)"])

Triggering Examples (violation is marked with '↓'):

Example #1

let foo = [1, 2, 3,]

Example #2

let foo = [1, 2, 3, ]

Example #3

let foo = [1, 2, 3   ,]

Example #4

let foo = [1: 2, 2: 3, ]

Example #5

struct Bar {
 let foo = [1: 2, 2: 3, ]
}

Example #6

let foo = [1, 2, 3,] + [4, 5, 6,]

Example #7

let example = [ 1,
2,
 // 3,
]

Void Return (void_return)

Prefer -> Void over -> ().

Non-triggering Examples:

Example #1

let abc: () -> Void = {}

Example #2

func foo(completion: () -> Void)

Example #3

let foo: (ConfigurationTests) -> () throws -> Void)

Example #4

let foo: (ConfigurationTests) ->   () throws -> Void)

Example #5

let foo: (ConfigurationTests) ->() throws -> Void)

Example #6

let foo: (ConfigurationTests) -> () -> Void)

Triggering Examples (violation is marked with '↓'):

Example #1

let abc: () ->() = {}

Example #2

func foo(completion: () ->())

Example #3

func foo(completion: () ->(   ))

Example #4

let foo: (ConfigurationTests) -> () throws ->())

Valid IBInspectable (valid_ibinspectable)

@IBInspectable should be applied to variables only, have its type explicit and be of a supported type

Non-triggering Examples:

Example #1

class Foo {
  @IBInspectable private var x: Int
}

Example #2

class Foo {
  @IBInspectable private var x: String?
}

Example #3

class Foo {
  @IBInspectable private var x: String!
}

Example #4

class Foo {
  @IBInspectable private var count: Int = 0
}

Example #5

class Foo {
  private var notInspectable = 0
}

Example #6

class Foo {
  private let notInspectable: Int
}

Example #7

class Foo {
  private let notInspectable: UInt8
}

Triggering Examples (violation is marked with '↓'):

Example #1

class Foo {
  @IBInspectable private let count: Int
}

Example #2

class Foo {
  @IBInspectable private var insets: UIEdgeInsets
}

Example #3

class Foo {
  @IBInspectable private var count = 0
}

Example #4

class Foo {
  @IBInspectable private var count: Int?
}

Example #5

class Foo {
  @IBInspectable private var count: Int!
}

Example #6

class Foo {
  @IBInspectable private var x: ImplicitlyUnwrappedOptional<Int>
}

Example #7

class Foo {
  @IBInspectable private var count: Optional<Int>
}

Example #8

class Foo {
  @IBInspectable private var x: Optional<String>
}

Example #9

class Foo {
  @IBInspectable private var x: ImplicitlyUnwrappedOptional<String>
}

Opening Brace Spacing (opening_brace)

Opening braces should be preceded by a single space and on the same line as the declaration.

Non-triggering Examples:

Example #1

func abc() {
}

Example #2

[].map() { $0 }

Example #3

[].map({ })

Example #4

if let a = b { }

Example #5

while a == b { }

Example #6

guard let a = b else { }

Example #7

if
	let a = b,
	let c = d
	where a == c
{ }

Example #8

while
	let a = b,
	let c = d
	where a == c
{ }

Example #9

guard
	let a = b,
	let c = d
	where a == c else
{ }

Triggering Examples (violation is marked with '↓'):

Example #1

func abc(){
}

Example #2

func abc()
	{ }

Example #3

[].map(){ $0 }

Example #4

[].map( { } )

Example #5

if let a = b{ }

Example #6

while a == b{ }

Example #7

guard let a = b else{ }

Example #8

if
	let a = b,
	let c = d
	where a == c{ }

Example #9

while
	let a = b,
	let c = d
	where a == c{ }

Example #10

guard
	let a = b,
	let c = d
	where a == c else{ }

Line Length (line_length)

Lines should not span too many characters.

Non-triggering Examples:

Example #1

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Example #2

#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)

Example #3

#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 (violation is marked with '↓'):

Example #1

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Example #2

#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)

Example #3

#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

Redundant Discardable Let (redundant_discardable_let)

Prefer _ = foo() over let _ = foo() when discarding a result from a function.

Non-triggering Examples:

Example #1

_ = foo()

Example #2

if let _ = foo() { }

Example #3

guard let _ = foo() else { return }

Example #4

let _: ExplicitType = foo()

Triggering Examples (violation is marked with '↓'):

Example #1

let _ = foo()

Example #2

if _ = foo() { let _ = bar() }

Weak Delegate (weak_delegate)

Delegates should be weak to avoid reference cycles.

Non-triggering Examples:

Example #1

class Foo {
  weak var delegate: SomeProtocol?
}

Example #2

class Foo {
  weak var someDelegate: SomeDelegateProtocol?
}

Example #3

class Foo {
  weak var delegateScroll: ScrollDelegate?
}

Example #4

class Foo {
  var scrollHandler: ScrollDelegate?
}

Example #5

func foo() {
  var delegate: SomeDelegate
}

Example #6

class Foo {
  var delegateNotified: Bool?
}

Example #7

protocol P {
 var delegate: AnyObject? { get set }
}

Example #8

class Foo {
 protocol P {
 var delegate: AnyObject? { get set }
}
}

Example #9

class Foo {
 var computedDelegate: ComputedDelegate {
 return bar() 
} 
}

Triggering Examples (violation is marked with '↓'):

Example #1

class Foo {
  var delegate: SomeProtocol?
}

Example #2

class Foo {
  var scrollDelegate: ScrollDelegate?
}

Force Try (force_try)

Force tries should be avoided.

Non-triggering Examples:

Example #1

func a() throws {}; do { try a() } catch {}

Triggering Examples (violation is marked with '↓'):

Example #1

func a() throws {}; try! a()

Redundant String Enum Value (redundant_string_enum_value)

String enum values can be omitted when they are equal to the enumcase name.

Non-triggering Examples:

Example #1

enum Numbers: String {
 case one
 case two
}

Example #2

enum Numbers: Int {
 case one = 1
 case two = 2
}

Example #3

enum Numbers: String {
 case one = "ONE"
 case two = "TWO"
}

Example #4

enum Numbers: String {
 case one = "ONE"
 case two = "two"
}

Example #5

enum Numbers: String {
 case one, two
}

Triggering Examples (violation is marked with '↓'):

Example #1

enum Numbers: String {
 case one = "one"
 case two = "two"
}

Example #2

enum Numbers: String {
 case one = "one", two = "two"
}

Example #3

enum Numbers: String {
 case one, two = "two"
}

File Line Length (file_length)

Files should not span too many lines.

Non-triggering Examples:

Example #1

//
//
...
//
//

Triggering Examples (violation is marked with '↓'):

Example #1

//
//
...
//
//

Program ended with exit code: 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment