let_var_whitespace - ApplebaumIan/BitbucketAPI GitHub Wiki

Variable Declaration Whitespace

Let and var should be separated from other statements by a blank line.

  • Identifier: let_var_whitespace
  • Enabled by default: Disabled
  • Supports autocorrection: No
  • Kind: style
  • Analyzer rule: No
  • Minimum Swift compiler version: 3.0.0
  • Default configuration: warning

Non Triggering Examples

let a = 0
var x = 1

x = 2

a = 5

var x = 1

struct X {
	var a = 0
}

let a = 1 +
	2
let b = 5

var x: Int {
	return 0
}

var x: Int {
	let a = 0

	return a
}

#if os(macOS)
let a = 0
#endif

#warning("TODO: remove it")
let a = 0

#error("TODO: remove it")
let a = 0

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

@available(OSX, introduced: 10.6)
@available(*, deprecated)
var x = 0

// swiftlint:disable superfluous_disable_command
// swiftlint:disable force_cast

let x = bar as! Bar
var x: Int {
	let a = 0
	return a
}

Triggering Examples

var x = 1
↓x = 2


a = 5
↓var x = 1

struct X {
	let a
	↓func x() {}
}

var x = 0
↓@objc func f() {}

var x = 0
↓@objc
	func f() {}

@objc func f() {
}
↓var x = 0