-
Notifications
You must be signed in to change notification settings - Fork 10.5k
network-comments: Added comments, fixed a few typos, and removed conditional parentheses for consistency #19108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…itional parentheses for consistency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch on the typos!
Documentation for protocol methods is inherited, so please don't override them unless there's something additional to say specifically about that implementation, and if doing so make sure to copy the original documentation over and make any appropriate changes.
Also, please remove unrelated whitespace changes.
@@ -22,6 +22,7 @@ public struct NWInterface : Hashable, CustomDebugStringConvertible { | |||
return self.name | |||
} | |||
|
|||
/// Comparison function to determine the equality of two network interfaces by name and kernel index. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Protocol requirements inherit documentation also. Only override if there's something specific to add here; it is not necessary to point out that ==
is a comparison function: that is a semantic guarantee of Equatable
(and therefore Hashable
). See the Equatable
protocol and elsewhere for standard phrasing for documentation. Here, it is sufficient simply to remove this comment altogether.
let host = NWEndpoint.Host.name(String(cString: nw_endpoint_get_hostname(nw)), interface) | ||
self = .hostPort(host: host, port: NWEndpoint.Port(nw_endpoint_get_port(nw))) | ||
} else if (nw_endpoint_get_type(nw) == Network.nw_endpoint_type_address) { | ||
} else if nw_endpoint_get_type(nw) == Network.nw_endpoint_type_address { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the added empty lines, here and above.
@@ -630,31 +630,32 @@ public enum NWEndpoint: Hashable, CustomDebugStringConvertible { | |||
if let nwinterface = nw_endpoint_copy_interface(nw) { | |||
interface = NWInterface(nwinterface) | |||
} | |||
if (nw_endpoint_get_type(nw) == Network.nw_endpoint_type_host) | |||
{ | |||
if nw_endpoint_get_type(nw) == Network.nw_endpoint_type_host{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If an opening brace is to be moved to the same line, a space should precede the brace.
@@ -524,7 +524,7 @@ public enum NWEndpoint: Hashable, CustomDebugStringConvertible { | |||
return interface | |||
} | |||
} | |||
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert this whitespace change.
@@ -434,7 +434,7 @@ public struct IPv6Address: IPAddress, Hashable, CustomDebugStringConvertible { | |||
hasher.combine(self.interface) | |||
} | |||
|
|||
// CustomDebugStringConvertible | |||
/// CustomDebugStringConvertible returning a debug description string of the IPv6 address and interface or just the address. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original comment should either be preserved as it was or removed; again, documentation is inherited and one should not override unless there's something in particular to be stated about this implementation. Generally, the specific contents of the debug description are not written out in documentation as they may change.
result = String(cString: storage) | ||
} | ||
storage.deallocate() | ||
return result ?? "?" | ||
} | ||
|
||
/// An IP address | ||
/// An IP address protocol |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swift documentation style describes protocols by the types that can conform; the word "protocol" is not used. For example, BinaryInteger
is documented as "An integer type with a binary representation." Here, IPAddress
is appropriately documented as "An IP address." It is not a protocol of protocols of internet protocol addresses :)
@@ -23,6 +23,7 @@ import _SwiftNetworkOverlayShims | |||
@available(macOS 10.14, iOS 12.0, watchOS 5.0, tvOS 12.0, *) | |||
public final class NWConnection : CustomDebugStringConvertible { | |||
|
|||
/// String based debugging representation of the NWConnection type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again here, do not override the inherited documentation for debugDescription
unless there's something specific to be described.
@@ -478,6 +479,7 @@ public final class NWConnection : CustomDebugStringConvertible { | |||
} | |||
} | |||
|
|||
/// Definition of callbacks used when sending data to the protocol stack. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see existing documentation for the prevailing style. "Definition of" is not used for definitions.
@@ -74,7 +75,7 @@ public struct NWInterface : Hashable, CustomDebugStringConvertible { | |||
} | |||
} | |||
} | |||
|
|||
// The interface type, such as other, wifi, cellular, wiredEthernet, and loopback. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unlike the case for strings (below), it isn't necessary to give "such as" examples here as there are only those options; that is, after all, the purpose of using an enumeration.
I think you meant for this to be a doc comment?
@@ -74,7 +75,7 @@ public struct NWInterface : Hashable, CustomDebugStringConvertible { | |||
} | |||
} | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert this deleted line.
@xwu Thank you for the feedback. Updating the PR now. |
@@ -478,6 +478,7 @@ public final class NWConnection : CustomDebugStringConvertible { | |||
} | |||
} | |||
|
|||
/// Callbacks used when sending data to the protocol stack. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be singular. It’s a type that’s a lot like Optional, so the documentation should be as well. Something like: “A type that represents either a wrapped completion handler invoked when send content has been consumed by the protocol stack, or the lack of a completion handler because the content is idempotent.”
if (nw_endpoint_get_type(nw) == Network.nw_endpoint_type_host) | ||
{ | ||
if nw_endpoint_get_type(nw) == Network.nw_endpoint_type_host { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this empty line.
@@ -74,7 +74,8 @@ public struct NWInterface : Hashable, CustomDebugStringConvertible { | |||
} | |||
} | |||
} | |||
|
|||
|
|||
/// The interface types wifi, cellular, wiredEthernet, and loopback. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be singular; i.e., “The interface type.” Again, an enumeration doesn’t need to be enumerated in the documentation.
Thank you @xwu. PR has been updated again. |
@@ -75,6 +75,7 @@ public struct NWInterface : Hashable, CustomDebugStringConvertible { | |||
} | |||
} | |||
|
|||
/// The interface type wifi, cellular, wiredEthernet, and loopback. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great. Last thing: to clarify my previous comment again, please remove "wifi, cellular, wiredEthernet, and loopback". That information is inherent in the fact that InterfaceType is an enumeration with only those cases. Moreover, it's documented in the comment for NWInterface itself.
@xwu Thank you. PR updated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@swift-ci Please smoke test |
…itional parentheses for consistency
Added comments to public methods and variables.
Fixed a few typos.
Removed parentheses from conditionals for consistency.
No open Jira ticket currently for this PR.