Skip to content

Commit

Permalink
fix Swift 5 warnings (mostly redundant modifiers (#642)
Browse files Browse the repository at this point in the history
Motivation:

Swift 5 complains on redundant modifiers. For example declaring a
`public func` inside of a `public extension` is now a warning. I don't
agree with this but I dislike warnings even more, so...

Modifications:

remove all redundant modifiers that the compiler now warns about such as

    swift-nio/Sources/NIOPriorityQueue/PriorityQueue.swift:90:5: warning: 'public' modifier is redundant for property declared in a public extension

Result:

no warnings in Swift 5
  • Loading branch information
weissi authored and Lukasa committed Nov 1, 2018
1 parent 054f65e commit 26bee21
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Sources/NIO/BlockingIOThreadPool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public extension BlockingIOThreadPool {
/// - eventLoop: The `EventLoop` the returned `EventLoopFuture` will fire on.
/// - body: The closure which performs some blocking work to be done on the thread pool.
/// - returns: The `EventLoopFuture` of `promise` fulfilled with the result (or error) of the passed closure.
public func runIfActive<T>(eventLoop: EventLoop, _ body: @escaping () throws -> T) -> EventLoopFuture<T> {
func runIfActive<T>(eventLoop: EventLoop, _ body: @escaping () throws -> T) -> EventLoopFuture<T> {
let promise: EventLoopPromise<T> = eventLoop.newPromise()
self.submit { shouldRun in
guard case shouldRun = BlockingIOThreadPool.WorkItemState.active else {
Expand Down
4 changes: 2 additions & 2 deletions Sources/NIO/ByteBuffer-views.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public struct ByteBufferView: ContiguousCollection, RandomAccessCollection {

public extension ByteBuffer {
/// A view into the readable bytes of the `ByteBuffer`.
public var readableBytesView: ByteBufferView {
var readableBytesView: ByteBufferView {
return ByteBufferView(buffer: self, range: self.readerIndex ..< self.readerIndex + self.readableBytes)
}

Expand All @@ -73,7 +73,7 @@ public extension ByteBuffer {
/// - index: The index the view should start at
/// - length: The length of the view (in bytes)
/// - returns A view into a portion of a `ByteBuffer`.
public func viewBytes(at index: Int, length: Int) -> ByteBufferView {
func viewBytes(at index: Int, length: Int) -> ByteBufferView {
return ByteBufferView(buffer: self, range: index ..< index+length)
}
}
12 changes: 6 additions & 6 deletions Sources/NIO/Channel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,29 +226,29 @@ public extension Channel {
/// Write data into the `Channel`, automatically wrapping with `NIOAny`.
///
/// - seealso: `ChannelOutboundInvoker.write`.
public func write<T>(_ any: T) -> EventLoopFuture<Void> {
func write<T>(_ any: T) -> EventLoopFuture<Void> {
return self.write(NIOAny(any))
}

/// Write data into the `Channel`, automatically wrapping with `NIOAny`.
///
/// - seealso: `ChannelOutboundInvoker.write`.
public func write<T>(_ any: T, promise: EventLoopPromise<Void>?) {
func write<T>(_ any: T, promise: EventLoopPromise<Void>?) {
self.write(NIOAny(any), promise: promise)
}

/// Write and flush data into the `Channel`, automatically wrapping with `NIOAny`.
///
/// - seealso: `ChannelOutboundInvoker.writeAndFlush`.
public func writeAndFlush<T>(_ any: T) -> EventLoopFuture<Void> {
func writeAndFlush<T>(_ any: T) -> EventLoopFuture<Void> {
return self.writeAndFlush(NIOAny(any))
}


/// Write and flush data into the `Channel`, automatically wrapping with `NIOAny`.
///
/// - seealso: `ChannelOutboundInvoker.writeAndFlush`.
public func writeAndFlush<T>(_ any: T, promise: EventLoopPromise<Void>?) {
func writeAndFlush<T>(_ any: T, promise: EventLoopPromise<Void>?) {
self.writeAndFlush(NIOAny(any), promise: promise)
}
}
Expand All @@ -270,7 +270,7 @@ public extension ChannelCore {
/// - as: The type to extract from the `NIOAny`.
/// - returns: The content of the `NIOAny`.
@_inlineable
public func unwrapData<T>(_ data: NIOAny, as: T.Type = T.self) -> T {
func unwrapData<T>(_ data: NIOAny, as: T.Type = T.self) -> T {
return data.forceAs()
}

Expand All @@ -283,7 +283,7 @@ public extension ChannelCore {
///
/// - parameters:
/// - channel: The `Channel` whose `ChannelPipeline` will be closed.
public func removeHandlers(channel: Channel) {
func removeHandlers(channel: Channel) {
channel.pipeline.removeHandlers()
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/NIO/EventLoopFuture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ public extension EventLoopFuture {
/// - parameters:
/// - target: The `EventLoop` that the returned `EventLoopFuture` will run on.
/// - returns: An `EventLoopFuture` whose callbacks run on `target` instead of the original loop.
public func hopTo(eventLoop target: EventLoop) -> EventLoopFuture<T> {
func hopTo(eventLoop target: EventLoop) -> EventLoopFuture<T> {
if target === self.eventLoop {
// We're already on that event loop, nothing to do here. Save an allocation.
return self
Expand Down
2 changes: 1 addition & 1 deletion Sources/NIO/PendingDatagramWritesManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fileprivate extension Error {
/// Returns whether the error is "recoverable" from the perspective of datagram sending.
///
/// - returns: `true` if the error is recoverable, `false` otherwise.
fileprivate var isRecoverable: Bool {
var isRecoverable: Bool {
switch self {
case let e as IOError where e.errnoCode == EMSGSIZE,
let e as IOError where e.errnoCode == EHOSTUNREACH:
Expand Down
2 changes: 1 addition & 1 deletion Sources/NIO/Selector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ struct SelectorEvent<R> {

internal extension Selector where R == NIORegistration {
/// Gently close the `Selector` after all registered `Channel`s are closed.
internal func closeGently(eventLoop: EventLoop) -> EventLoopFuture<Void> {
func closeGently(eventLoop: EventLoop) -> EventLoopFuture<Void> {
guard self.lifecycleState == .open else {
return eventLoop.newFailedFuture(error: IOError(errnoCode: EBADF, reason: "can't close selector gently as it's \(self.lifecycleState)."))
}
Expand Down
28 changes: 14 additions & 14 deletions Sources/NIO/SocketOptionProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ public extension SocketOptionProvider {
/// - value: The value to set SO_LINGER to.
/// - returns: An `EventLoopFuture` that fires when the option has been set,
/// or if an error has occurred.
public func setSoLinger(_ value: linger) -> EventLoopFuture<Void> {
func setSoLinger(_ value: linger) -> EventLoopFuture<Void> {
return self.unsafeSetSocketOption(level: SocketOptionLevel(SOL_SOCKET), name: SO_LINGER, value: value)
}

/// Gets the value of the socket option SO_LINGER.
///
/// - returns: An `EventLoopFuture` containing the value of the socket option, or
/// any error that occurred while retrieving the socket option.
public func getSoLinger() -> EventLoopFuture<linger> {
func getSoLinger() -> EventLoopFuture<linger> {
return self.unsafeGetSocketOption(level: SocketOptionLevel(SOL_SOCKET), name: SO_LINGER)
}

Expand All @@ -106,15 +106,15 @@ public extension SocketOptionProvider {
/// - value: The value to set IP_MULTICAST_IF to.
/// - returns: An `EventLoopFuture` that fires when the option has been set,
/// or if an error has occurred.
public func setIPMulticastIF(_ value: in_addr) -> EventLoopFuture<Void> {
func setIPMulticastIF(_ value: in_addr) -> EventLoopFuture<Void> {
return self.unsafeSetSocketOption(level: IPPROTO_IP, name: IP_MULTICAST_IF, value: value)
}

/// Gets the value of the socket option IP_MULTICAST_IF.
///
/// - returns: An `EventLoopFuture` containing the value of the socket option, or
/// any error that occurred while retrieving the socket option.
public func getIPMulticastIF() -> EventLoopFuture<in_addr> {
func getIPMulticastIF() -> EventLoopFuture<in_addr> {
return self.unsafeGetSocketOption(level: IPPROTO_IP, name: IP_MULTICAST_IF)
}

Expand All @@ -124,15 +124,15 @@ public extension SocketOptionProvider {
/// - value: The value to set IP_MULTICAST_TTL to.
/// - returns: An `EventLoopFuture` that fires when the option has been set,
/// or if an error has occurred.
public func setIPMulticastTTL(_ value: CUnsignedChar) -> EventLoopFuture<Void> {
func setIPMulticastTTL(_ value: CUnsignedChar) -> EventLoopFuture<Void> {
return self.unsafeSetSocketOption(level: IPPROTO_IP, name: IP_MULTICAST_TTL, value: value)
}

/// Gets the value of the socket option IP_MULTICAST_TTL.
///
/// - returns: An `EventLoopFuture` containing the value of the socket option, or
/// any error that occurred while retrieving the socket option.
public func getIPMulticastTTL() -> EventLoopFuture<CUnsignedChar> {
func getIPMulticastTTL() -> EventLoopFuture<CUnsignedChar> {
return self.unsafeGetSocketOption(level: IPPROTO_IP, name: IP_MULTICAST_TTL)
}

Expand All @@ -142,15 +142,15 @@ public extension SocketOptionProvider {
/// - value: The value to set IP_MULTICAST_LOOP to.
/// - returns: An `EventLoopFuture` that fires when the option has been set,
/// or if an error has occurred.
public func setIPMulticastLoop(_ value: CUnsignedChar) -> EventLoopFuture<Void> {
func setIPMulticastLoop(_ value: CUnsignedChar) -> EventLoopFuture<Void> {
return self.unsafeSetSocketOption(level: IPPROTO_IP, name: IP_MULTICAST_LOOP, value: value)
}

/// Gets the value of the socket option IP_MULTICAST_LOOP.
///
/// - returns: An `EventLoopFuture` containing the value of the socket option, or
/// any error that occurred while retrieving the socket option.
public func getIPMulticastLoop() -> EventLoopFuture<CUnsignedChar> {
func getIPMulticastLoop() -> EventLoopFuture<CUnsignedChar> {
return self.unsafeGetSocketOption(level: IPPROTO_IP, name: IP_MULTICAST_LOOP)
}

Expand All @@ -160,15 +160,15 @@ public extension SocketOptionProvider {
/// - value: The value to set IPV6_MULTICAST_IF to.
/// - returns: An `EventLoopFuture` that fires when the option has been set,
/// or if an error has occurred.
public func setIPv6MulticastIF(_ value: CUnsignedInt) -> EventLoopFuture<Void> {
func setIPv6MulticastIF(_ value: CUnsignedInt) -> EventLoopFuture<Void> {
return self.unsafeSetSocketOption(level: IPPROTO_IPV6, name: IPV6_MULTICAST_IF, value: value)
}

/// Gets the value of the socket option IPV6_MULTICAST_IF.
///
/// - returns: An `EventLoopFuture` containing the value of the socket option, or
/// any error that occurred while retrieving the socket option.
public func getIPv6MulticastIF() -> EventLoopFuture<CUnsignedInt> {
func getIPv6MulticastIF() -> EventLoopFuture<CUnsignedInt> {
return self.unsafeGetSocketOption(level: IPPROTO_IPV6, name: IPV6_MULTICAST_IF)
}

Expand All @@ -178,15 +178,15 @@ public extension SocketOptionProvider {
/// - value: The value to set IPV6_MULTICAST_HOPS to.
/// - returns: An `EventLoopFuture` that fires when the option has been set,
/// or if an error has occurred.
public func setIPv6MulticastHops(_ value: CInt) -> EventLoopFuture<Void> {
func setIPv6MulticastHops(_ value: CInt) -> EventLoopFuture<Void> {
return self.unsafeSetSocketOption(level: IPPROTO_IPV6, name: IPV6_MULTICAST_HOPS, value: value)
}

/// Gets the value of the socket option IPV6_MULTICAST_HOPS.
///
/// - returns: An `EventLoopFuture` containing the value of the socket option, or
/// any error that occurred while retrieving the socket option.
public func getIPv6MulticastHops() -> EventLoopFuture<CInt> {
func getIPv6MulticastHops() -> EventLoopFuture<CInt> {
return self.unsafeGetSocketOption(level: IPPROTO_IPV6, name: IPV6_MULTICAST_HOPS)
}

Expand All @@ -196,15 +196,15 @@ public extension SocketOptionProvider {
/// - value: The value to set IPV6_MULTICAST_LOOP to.
/// - returns: An `EventLoopFuture` that fires when the option has been set,
/// or if an error has occurred.
public func setIPv6MulticastLoop(_ value: CUnsignedInt) -> EventLoopFuture<Void> {
func setIPv6MulticastLoop(_ value: CUnsignedInt) -> EventLoopFuture<Void> {
return self.unsafeSetSocketOption(level: IPPROTO_IPV6, name: IPV6_MULTICAST_LOOP, value: value)
}

/// Gets the value of the socket option IPV6_MULTICAST_LOOP.
///
/// - returns: An `EventLoopFuture` containing the value of the socket option, or
/// any error that occurred while retrieving the socket option.
public func getIPv6MulticastLoop() -> EventLoopFuture<CUnsignedInt> {
func getIPv6MulticastLoop() -> EventLoopFuture<CUnsignedInt> {
return self.unsafeGetSocketOption(level: IPPROTO_IPV6, name: IPV6_MULTICAST_LOOP)
}
}
Expand Down
18 changes: 9 additions & 9 deletions Sources/NIOHTTP1/HTTPPipelineSetup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public extension ChannelPipeline {
/// or at the tail.
/// - returns: An `EventLoopFuture` that will fire when the pipeline is configured.
@available(*, deprecated, message: "Please use configureHTTPServerPipeline")
public func addHTTPServerHandlers(first: Bool = false) -> EventLoopFuture<Void> {
func addHTTPServerHandlers(first: Bool = false) -> EventLoopFuture<Void> {
return addHandlers(HTTPResponseEncoder(), HTTPRequestDecoder(), first: first)
}

Expand All @@ -38,7 +38,7 @@ public extension ChannelPipeline {
/// - first: Whether to add the HTTP client at the head of the channel pipeline,
/// or at the tail.
/// - returns: An `EventLoopFuture` that will fire when the pipeline is configured.
public func addHTTPClientHandlers(first: Bool = false) -> EventLoopFuture<Void> {
func addHTTPClientHandlers(first: Bool = false) -> EventLoopFuture<Void> {
return addHandlers(HTTPRequestEncoder(), HTTPResponseDecoder(), first: first)
}

Expand All @@ -54,9 +54,9 @@ public extension ChannelPipeline {
/// complete.
/// - returns: An `EventLoopFuture` that will fire when the pipeline is configured.
@available(*, deprecated, message: "Please use configureHTTPServerPipeline")
public func addHTTPServerHandlersWithUpgrader(first: Bool = false,
upgraders: [HTTPProtocolUpgrader],
_ upgradeCompletionHandler: @escaping (ChannelHandlerContext) -> Void) -> EventLoopFuture<Void> {
func addHTTPServerHandlersWithUpgrader(first: Bool = false,
upgraders: [HTTPProtocolUpgrader],
_ upgradeCompletionHandler: @escaping (ChannelHandlerContext) -> Void) -> EventLoopFuture<Void> {
let responseEncoder = HTTPResponseEncoder()
let requestDecoder = HTTPRequestDecoder(leftOverBytesStrategy: .forwardBytes)
let upgrader = HTTPServerUpgradeHandler(upgraders: upgraders,
Expand Down Expand Up @@ -93,10 +93,10 @@ public extension ChannelPipeline {
/// failure to parse the HTTP request) by sending 400 errors. Defaults to `false` for
/// backward-compatibility reasons.
/// - returns: An `EventLoopFuture` that will fire when the pipeline is configured.
public func configureHTTPServerPipeline(first: Bool = false,
withPipeliningAssistance pipelining: Bool = true,
withServerUpgrade upgrade: HTTPUpgradeConfiguration? = nil,
withErrorHandling errorHandling: Bool = false) -> EventLoopFuture<Void> {
func configureHTTPServerPipeline(first: Bool = false,
withPipeliningAssistance pipelining: Bool = true,
withServerUpgrade upgrade: HTTPUpgradeConfiguration? = nil,
withErrorHandling errorHandling: Bool = false) -> EventLoopFuture<Void> {
let responseEncoder = HTTPResponseEncoder()
let requestDecoder = HTTPRequestDecoder(leftOverBytesStrategy: upgrade == nil ? .dropBytes : .forwardBytes)

Expand Down
2 changes: 1 addition & 1 deletion Sources/NIOHTTP1/HTTPTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ public protocol _DeprecateHTTPHeaderIterator: Sequence { }
extension HTTPHeaders: _DeprecateHTTPHeaderIterator { }
public extension _DeprecateHTTPHeaderIterator {
@available(*, deprecated, message: "Please use the HTTPHeaders.Iterator type")
public func makeIterator() -> AnyIterator<Element> {
func makeIterator() -> AnyIterator<Element> {
return AnyIterator(makeIterator() as Iterator)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/NIOPriorityQueue/PriorityQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ extension PriorityQueue: Sequence {
@available(*, deprecated, message: "The NIOPriorityQueue module is deprecated and will be removed in the next major release.")
public extension PriorityQueue {
@available(*, deprecated, message: "The NIOPriorityQueue module is deprecated and will be removed in the next major release.")
public var count: Int {
var count: Int {
return self.heap.count
}
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/NIOWebSocket/WebSocketErrorCodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public extension ByteBuffer {
/// This method increments the reader index.
///
/// - returns: The error code, or `nil` if there were not enough readable bytes.
public mutating func readWebSocketErrorCode() -> WebSocketErrorCode? {
mutating func readWebSocketErrorCode() -> WebSocketErrorCode? {
return self.readInteger(as: UInt16.self).map { WebSocketErrorCode(networkInteger: $0) }
}

Expand All @@ -162,15 +162,15 @@ public extension ByteBuffer {
/// - parameters:
/// - index: The index into the buffer to read the error code from.
/// - returns: The error code, or `nil` if there were not enough bytes at that index.
public func getWebSocketErrorCode(at index: Int) -> WebSocketErrorCode? {
func getWebSocketErrorCode(at index: Int) -> WebSocketErrorCode? {
return self.getInteger(at: index, as: UInt16.self).map { WebSocketErrorCode(networkInteger: $0) }
}

/// Write the given error code to the buffer.
///
/// - parameters:
/// - code: The code to write into the buffer.
public mutating func write(webSocketErrorCode code: WebSocketErrorCode) {
mutating func write(webSocketErrorCode code: WebSocketErrorCode) {
self.write(integer: UInt16(webSocketErrorCode: code))
}
}
Expand All @@ -180,7 +180,7 @@ public extension UInt16 {
///
/// - parameters:
/// - code: The `WebSocketErrorCode`.
public init(webSocketErrorCode code: WebSocketErrorCode) {
init(webSocketErrorCode code: WebSocketErrorCode) {
switch code {
case .normalClosure:
self = 1000
Expand Down
6 changes: 3 additions & 3 deletions Sources/NIOWebSocket/WebSocketFrameDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public enum NIOWebSocketError: Error {
}

internal extension WebSocketErrorCode {
internal init(_ error: NIOWebSocketError) {
init(_ error: NIOWebSocketError) {
switch error {
case .invalidFrameLength:
self = .messageTooLarge
Expand All @@ -44,7 +44,7 @@ public extension ByteBuffer {
///
/// - parameters:
/// - maskingKey: The masking key.
public mutating func webSocketUnmask(_ maskingKey: WebSocketMaskingKey, indexOffset: Int = 0) {
mutating func webSocketUnmask(_ maskingKey: WebSocketMaskingKey, indexOffset: Int = 0) {
/// Shhhh: secretly unmasking and masking are the same operation!
webSocketMask(maskingKey, indexOffset: indexOffset)
}
Expand All @@ -57,7 +57,7 @@ public extension ByteBuffer {
/// This is used when masking multiple "contiguous" byte buffers, to ensure that
/// the masking key is applied uniformly to the collection rather than from the
/// start each time.
public mutating func webSocketMask(_ maskingKey: WebSocketMaskingKey, indexOffset: Int = 0) {
mutating func webSocketMask(_ maskingKey: WebSocketMaskingKey, indexOffset: Int = 0) {
self.withUnsafeMutableReadableBytes {
for (index, byte) in $0.enumerated() {
$0[index] = byte ^ maskingKey[(index + indexOffset) % 4]
Expand Down
2 changes: 1 addition & 1 deletion Sources/NIOWebSocket/WebSocketOpcode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public extension UInt8 {
///
/// - parameters:
/// - opcode: The `WebSocketOpcode`.
public init?(webSocketOpcode opcode: WebSocketOpcode) {
init?(webSocketOpcode opcode: WebSocketOpcode) {
switch opcode {
case .continuation:
self = 0x0
Expand Down
2 changes: 1 addition & 1 deletion Sources/NIOWebSocket/WebSocketUpgrader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public enum NIOWebSocketUpgradeError: Error {
}

fileprivate extension HTTPHeaders {
fileprivate func nonListHeader(_ name: String) throws -> String {
func nonListHeader(_ name: String) throws -> String {
let fields = self[canonicalForm: name]
guard fields.count == 1 else {
throw NIOWebSocketUpgradeError.invalidUpgradeHeader
Expand Down
Loading

0 comments on commit 26bee21

Please sign in to comment.