Prefer checking isEmpty
over comparing count
to zero.
Example #1
var count = 0
Example #2
[Int]().isEmpty
Example #3
[Int]().count > 1
Example #4
[Int]().count == 1
Example #1
[Int]().↓count == 0
Example #2
[Int]().↓count > 0
Example #3
[Int]().↓count != 0
Initializing an optional variable with nil is redundant.
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
}()
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
Lines should not have trailing semicolons.
Example #1
let a = 0
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↓; ; ;
Else and catch should be on the same line, one space after the previous declaration.
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
)
Example #1
↓}else if {
Example #2
↓} else {
Example #3
↓}
catch {
Example #4
↓}
catch {
Type name should only contain alphanumeric characters, start with an uppercase character and span between 3 and 40 characters in length.
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
}
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
}
When the index or the item is not used, .enumerated()
can be removed.
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 { }
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() { }
TODOs and FIXMEs should be avoided.
Example #1
// notaTODO:
Example #2
// notaFIXME:
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: */
Properties should have a type interface
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
}
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
}
Struct-scoped constants are preferred over legacy global constants.
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
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 casts should be avoided.
Example #1
NSNumber() as? Int
Example #1
NSNumber() ↓as! Int
Prefer Nimble operator overloads over free matcher functions.
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))
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 parameter in a closure should be replaced 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 { _ 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
}
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
}
Underscores should be used as thousand separator in large decimal numbers.
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
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
There should be no space before and one after any comma.
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
) {
}
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
)
Imports should be sorted.
Example #1
import AAA
import BBB
import CCC
import DDD
Example #2
import Alamofire
import API
Example #3
import labc
import Ldef
Example #1
import AAA
import ZZZ
import ↓BBB
import CCC
Computed read-only properties should avoid using the get keyword.
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
}
}
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
}
}
}
Struct extension properties and methods are preferred over legacy functions
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)
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 should be avoided.
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)
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"]↓! }
Files should not contain leading whitespace.
Example #1
//
Example #1
Example #2
//
Complexity of function bodies should be limited.
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 {}
}}
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
}
}
}
if,for,while,do statements shouldn't wrap their conditionals in parentheses.
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 {
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) {
Functions bodies should not span too many lines.
When using trailing closures, empty parentheses should be avoided after the method call.
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
()
})
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
}
avoid using 'dynamic' and '@inline(__always)' together.
Example #1
class C {
dynamic func f() {}}
Example #2
class C {
@inline(__always) func f() {}}
Example #3
class C {
@inline(never) dynamic func f() {}}
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 bodies should not span too many lines.
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
*/
}
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
}
Prefer != nil
over let _ =
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 }) {}
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 {}
Operators should be surrounded by a single whitespace when defining them.
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 {}
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 expressions should have a single space inside each brace.
Example #1
[].map ({ $0.description })
Example #2
[].filter { $0.contains(location) }
Example #3
extension UITableViewCell: ReusableView { }
Example #4
extension UITableViewCell: ReusableView {}
Example #1
[].filter(↓{$0.contains(location)})
Example #2
[].map(↓{$0})
Some methods should not call super
Example #1
class VC: UIViewController {
override func loadView() {
}
}
Example #2
class NSView {
func updateLayer() {
self.method1() }
}
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()
}
}
Prefer object literals over image and color inits.
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)
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)
Documented declarations should be valid.
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 }
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 }
Limit vertical whitespace to a single empty line.
Example #1
let abc = 0
Example #2
let abc = 0
Example #3
/* bcs
*/
Example #4
// bca
Example #1
let aaaa = 0
Example #2
struct AAAA {}
Example #3
class BBBB {}
Returning Void in a function declaration is redundant.
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 -> ()
Example #1
func foo()↓ -> Void {}
Example #2
protocol Foo {
func foo()↓ -> Void
}
Example #3
func foo()↓ -> () {}
Example #4
protocol Foo {
func foo()↓ -> ()
}
Tuples shouldn't have too many members. Create a custom type instead.
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)?
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)?
Lines should not have trailing whitespace.
Example #1
let name: String
Example #2
//
Example #3
//
Example #4
let name: String //
Example #5
let name: String //
Example #1
let name: String
Example #2
/* */ let name: String
MARK comment should be in valid format.
Example #1
// MARK: good
Example #2
// MARK: - good
Example #3
// MARK: -
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
Prefer () ->
over Void ->
.
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)
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)
Struct extension properties and methods are preferred over legacy functions
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)
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 optionals should be avoided when possible.
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
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 with closing parenthesis should not have any whitespaces in the middle.
Example #1
[].map({ })
Example #2
[].map(
{ }
)
Example #1
[].map({ ↓} )
Example #2
[].map({ ↓} )
An object should only remove itself as an observer in deinit
.
Example #1
class Foo {
deinit {
NotificationCenter.default.removeObserver(self)
}
}
Example #2
class Foo {
func bar() {
NotificationCenter.default.removeObserver(otherObject)
}
}
Example #1
class Foo {
func bar() {
↓NotificationCenter.default.removeObserver(self)
}
}
Delegate protocols should be class-only so they can be weakly referenced.
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 {}
Example #1
↓protocol FooDelegate {}
Example #2
↓protocol FooDelegate: Bar {}
Colons should be next to the identifier when specifying a type and next to the key in dictionary literals.
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"]
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]
Prefer shorthand operators (+=, -=, *=, /=) over doing the operation and assigning.
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
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 parameters should be on the same line as opening brace.
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)
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
}
Types should be nested at most 1 level deep, and statements should be nested at most 5 levels deep.
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 } }
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() {
}
}
}
}
}
}
}
Cases inside a switch should always be on a newline
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
}
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
}
Files should have consistent header comments.
Example #1
let foo = "Copyright"
Example #2
let foo = 2 // Copyright
Example #3
let foo = 2
// Copyright
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 statements should always return on the next line
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 }
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" }
Files should have a single trailing newline.
Example #1
let a = 0
Example #1
let a = 0
Example #2
let a = 0
Public declarations should be documented.
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() } }
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
}
where
clauses are preferred over a single if
inside a for
.
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 { }
}
Example #1
for user in users {
↓if user.id == 1 { return true }
}
nil coalescing operator is only evaluated if the lhs is nil, coalescing operator with nil as rhs is redundant
Example #1
var myVar: Int?; myVar ?? 0
Example #1
var myVar: Int? = nil; myVar↓ ?? nil
Example #2
var myVar: Int? = nil; myVar↓??nil
Unit tests marked private are silently skipped.
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() {}
}
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() {}
private ↓func test4() {}
}
Example #3
internal class FooTest: XCTestCase { func test1() {}
internal func test2() {}
public func test3() {}
private ↓func test4() {}
}
Example #4
public class FooTest: XCTestCase { func test1() {}
internal func test2() {}
public func test3() {}
private ↓func test4() {}
}
The initializers declared in compiler protocols such as ExpressibleByArrayLiteral
shouldn't be called directly.
Example #1
let set: Set<Int> = [1, 2]
Example #2
let set = Set(array)
Example #1
let set = ↓Set(arrayLiteral: 1, 2)
Example #2
let set = ↓Set.init(arrayLiteral: 1, 2)
Return arrow and return type should be separated by a single space or on a separate line.
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 {}
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 }
Operators should be surrounded by a single whitespace when they are being used.
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
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 should be on their own lines in functions and types, but on the same line as variables and imports.
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)
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
Some overridden methods should always call super
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) {
}
}
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() ↓{
}
}
A fatalError call should have a message.
Example #1
func foo() {
fatalError("Foo")
}
Example #2
func foo() {
fatalError(x)
}
Example #1
func foo() {
↓fatalError("")
}
Example #2
func foo() {
↓fatalError()
}
Function parameters should be aligned vertically if they're in multiple lines in a declaration.
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
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]) { }
Prefer using .first(where:)
over .filter { }.first
in collections.
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 }
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
IBOutlets should be private to avoid leaking UIKit to higher layers.
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?
}
Example #1
class Foo {
@IBOutlet ↓var label: UILabel?
}
Example #2
class Foo {
@IBOutlet ↓var label: UILabel!
}
Generic type name should only contain alphanumeric characters, start with an uppercase character and span between 1 and 20 characters in length.
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>
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> {}
Explicitly calling .init() should be avoided.
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) }
Example #1
[1].flatMap{String↓.init($0)}
Example #2
[String.self].map { Type in Type↓.init(1) }
Swift constructors are preferred over legacy convenience functions.
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)
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)
When registing for a notification using a block, the opaque observer that is returned should be stored so it can be removed later.
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: { })
Example #1
↓nc.addObserver(forName: .NSSystemTimeZoneDidChange, object: nil, queue: nil) { }
Example #2
↓nc.addObserver(forName: .NSSystemTimeZoneDidChange, object: nil, queue: nil, using: { })
Closure end should have the same indentation as the line that started it.
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 }
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 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.
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
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 }
Create custom rules by providing a regex string. Optionally specify what syntax kinds to match against, the severity level, and what message to display.
Number of function parameters should be low.
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] } ?? []}}
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) {}}
Shorthand syntactic sugar should be used, i.e. [Int] instead of Array
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
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 commas in arrays and dictionaries should be avoided/enforced.
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)"])
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,
]
Prefer -> Void
over -> ()
.
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)
Example #1
let abc: () -> ↓() = {}
Example #2
func foo(completion: () -> ↓())
Example #3
func foo(completion: () -> ↓( ))
Example #4
let foo: (ConfigurationTests) -> () throws -> ↓())
@IBInspectable should be applied to variables only, have its type explicit and be of a supported type
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
}
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 braces should be preceded by a single space and on the same line as the declaration.
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
{ }
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{ }
Lines should not span too many characters.
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")
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
Prefer _ = foo()
over let _ = foo()
when discarding a result from a function.
Example #1
_ = foo()
Example #2
if let _ = foo() { }
Example #3
guard let _ = foo() else { return }
Example #4
let _: ExplicitType = foo()
Example #1
↓let _ = foo()
Example #2
if _ = foo() { ↓let _ = bar() }
Delegates should be weak to avoid reference cycles.
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()
}
}
Example #1
class Foo {
↓var delegate: SomeProtocol?
}
Example #2
class Foo {
↓var scrollDelegate: ScrollDelegate?
}
Force tries should be avoided.
Example #1
func a() throws {}; do { try a() } catch {}
Example #1
func a() throws {}; ↓try! a()
String enum values can be omitted when they are equal to the enumcase name.
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
}
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"
}
Files should not span too many lines.
Example #1
//
//
...
//
//
Example #1
//
//
...
//
//
Program ended with exit code: 0