Extension Access Modifier

Prefer to use extension access modifiers

  • Identifier: extension_access_modifier
  • Enabled by default: No
  • Supports autocorrection: No
  • Kind: idiomatic
  • Analyzer rule: No
  • Minimum Swift compiler version: 5.0.0
  • Default configuration:
    KeyValue
    severity warning

Non Triggering Examples

extension Foo: SomeProtocol {
  public var bar: Int { return 1 }
}
extension Foo {
  private var bar: Int { return 1 }
  public var baz: Int { return 1 }
}
extension Foo {
  private var bar: Int { return 1 }
  public func baz() {}
}
extension Foo {
  var bar: Int { return 1 }
  var baz: Int { return 1 }
}
extension Foo {
  var bar: Int { return 1 }
  internal var baz: Int { return 1 }
}
internal extension Foo {
  var bar: Int { return 1 }
  var baz: Int { return 1 }
}
public extension Foo {
  var bar: Int { return 1 }
  var baz: Int { return 1 }
}
public extension Foo {
  var bar: Int { return 1 }
  internal var baz: Int { return 1 }
}
extension Foo {
  private var bar: Int { return 1 }
  private var baz: Int { return 1 }
}
extension Foo {
  open var bar: Int { return 1 }
  open var baz: Int { return 1 }
}
extension Foo {
    func setup() {}
    public func update() {}
}
private extension Foo {
  private var bar: Int { return 1 }
  var baz: Int { return 1 }
}
extension Foo {
  internal private(set) var bar: Int {
    get { Foo.shared.bar }
    set { Foo.shared.bar = newValue }
  }
}
extension Foo {
  private(set) internal var bar: Int {
    get { Foo.shared.bar }
    set { Foo.shared.bar = newValue }
  }
}
public extension Foo {
  private(set) var value: Int { 1 }
}

Triggering Examples

extension Foo {
   public var bar: Int { return 1 }
   public var baz: Int { return 1 }
}
extension Foo {
   public var bar: Int { return 1 }
   public func baz() {}
}
public extension Foo {
  public func bar() {}
  public func baz() {}
}
extension Foo {
   public var bar: Int {
      let value = 1
      return value
   }

   public var baz: Int { return 1 }
}
extension Array where Element: Equatable {
    public var unique: [Element] {
        var uniqueValues = [Element]()
        for item in self where !uniqueValues.contains(item) {
            uniqueValues.append(item)
        }
        return uniqueValues
    }
}
extension Foo {
   #if DEBUG
   public var bar: Int {
      let value = 1
      return value
   }
   #endif

   public var baz: Int { return 1 }
}
public extension Foo {
  private func bar() {}
  private func baz() {}
}
extension Foo {
  private(set) public var value: Int { 1 }
}