Variable Declaration Whitespace
Variable declarations should be separated from other statements by a blank line
- Identifier:
let_var_whitespace
- Enabled by default: No
- Supports autocorrection: No
- Kind: style
- Analyzer rule: No
- Minimum Swift compiler version: 5.0.0
- Default configuration:
Key Value severity warning
Non Triggering Examples
class C {
let a = 0
var x = 1
var y = 2
}
class C {
let a = 5
var x = 1
}
class C {
var a = 0
}
class C {
let a = 1 +
2
let b = 5
}
class C {
var x: Int {
return 0
}
}
class C {
var x: Int {
let a = 0
return a
}
}
class C {
#if os(macOS)
let a = 0
func f() {}
#endif
}
class C {
#warning("TODO: remove it")
let a = 0
#warning("TODO: remove it")
let b = 0
}
class C {
#error("TODO: remove it")
let a = 0
}
class C {
@available(swift 4)
let a = 0
}
class C {
@objc
var s: String = ""
}
class C {
@objc
func a() {}
}
class C {
var x = 0
lazy
var y = 0
}
class C {
@available(OSX, introduced: 10.6)
@available(*, deprecated)
var x = 0
}
class C {
// swiftlint:disable superfluous_disable_command
// swiftlint:disable force_cast
let x = bar as! Bar
}
class C {
@available(swift 4)
@UserDefault("param", defaultValue: true)
var isEnabled = true
@Attribute
func f() {}
}
class C {
var x: Int {
let a = 0
return a
}
}
a = 2
a = 2
var b = 3
#warning("message")
let a = 2
#if os(macOS)
let a = 2
#endif
f {
let a = 1
return a
}
func f() {
#if os(macOS)
let a = 2
return a
#else
return 1
#endif
}
Triggering Examples
class C {
let a
↓func x() {}
}
class C {
var x = 0
↓@objc func f() {}
}
class C {
var x = 0
↓@objc
func f() {}
}
class C {
@objc func f() {
}
↓var x = 0
}
class C {
func f() {}
↓@Wapper
let isNumber = false
@Wapper
var isEnabled = true
↓func g() {}
}
class C {
#if os(macOS)
let a = 0
↓func f() {}
#endif
}
let a = 2
↓b = 1