Skip to content

Files

Latest commit

 

History

History
40 lines (29 loc) · 699 Bytes

prefer_self_in_static_references.md

File metadata and controls

40 lines (29 loc) · 699 Bytes

Pattern: Missing use of Self for static reference

Issue: -

Description

Static references should be prefixed by Self instead of the class name.

Examples of correct code:

class C {
	static private(set) var i = 0, j = C.i
	let h = C.i
	@GreaterThan(C.j) var k: Int
}

class `Self` {
	static let i = 0
	func f() -> Int { Self.i }
}

Examples of incorrect code:

struct C {
	static let i = 0
	static let j = C.i
}

struct S {
	static let i = 0
	func f() -> Int { S.i }
}

Further Reading