Discouraged None Name
Enum cases and static members named none
are discouraged as they can conflict with Optional<T>.none
.
- Identifier:
discouraged_none_name
- Enabled by default: No
- Supports autocorrection: No
- Kind: idiomatic
- Analyzer rule: No
- Minimum Swift compiler version: 5.0.0
- Default configuration:
Key Value severity warning
Non Triggering Examples
enum MyEnum {
case nOne
}
enum MyEnum {
case _none
}
enum MyEnum {
case none_
}
enum MyEnum {
case none(Any)
}
enum MyEnum {
case nonenone
}
class MyClass {
class var nonenone: MyClass { MyClass() }
}
class MyClass {
static var nonenone = MyClass()
}
class MyClass {
static let nonenone = MyClass()
}
struct MyStruct {
static var nonenone = MyStruct()
}
struct MyStruct {
static let nonenone = MyStruct()
}
struct MyStruct {
let none = MyStruct()
}
struct MyStruct {
var none = MyStruct()
}
class MyClass {
let none = MyClass()
}
class MyClass {
var none = MyClass()
}
Triggering Examples
enum MyEnum {
case ↓none
}
enum MyEnum {
case a, ↓none
}
enum MyEnum {
case ↓none, b
}
enum MyEnum {
case a, ↓none, b
}
enum MyEnum {
case a
case ↓none
}
enum MyEnum {
case ↓none
case b
}
enum MyEnum {
case a
case ↓none
case b
}
class MyClass {
↓static let none = MyClass()
}
class MyClass {
↓static let none: MyClass = MyClass()
}
class MyClass {
↓static var none: MyClass = MyClass()
}
class MyClass {
↓class var none: MyClass { MyClass() }
}
struct MyStruct {
↓static var none = MyStruct()
}
struct MyStruct {
↓static var none: MyStruct = MyStruct()
}
struct MyStruct {
↓static var none = MyStruct()
}
struct MyStruct {
↓static var none: MyStruct = MyStruct()
}
struct MyStruct {
↓static var a = MyStruct(), none = MyStruct()
}
struct MyStruct {
↓static var none = MyStruct(), a = MyStruct()
}