Prefixed Top-Level Constant

Top-level constants should be prefixed by k

  • Identifier: prefixed_toplevel_constant
  • Enabled by default: No
  • Supports autocorrection: No
  • Kind: style
  • Analyzer rule: No
  • Minimum Swift compiler version: 5.0.0
  • Default configuration:
    KeyValue
    severity warning
    only_private false

Non Triggering Examples

private let kFoo = 20.0
public let kFoo = false
internal let kFoo = "Foo"
let kFoo = true
//
// only_private: true
//

let Foo = true

struct Foo {
    let bar = 20.0
}
private var foo = 20.0
public var foo = false
internal var foo = "Foo"
var foo = true
var foo = true, bar = true
var foo = true, let kFoo = true
let
    kFoo = true
var foo: Int {
    return a + b
}
let kFoo = {
    return a + b
}()
var foo: String {
    let bar = ""
    return bar
}
if condition() {
    let result = somethingElse()
    print(result)
    exit()
}
[1, 2, 3, 1000, 4000].forEach { number in
    let isSmall = number < 10
    if isSmall {
        print("\(number) is a small number")
    }
}

Triggering Examples

private let Foo = 20.0
public let Foo = false
internal let Foo = "Foo"
let Foo = true
let foo = 2, bar = true
let
    foo = true
let foo = {
    return a + b
}()