-
Notifications
You must be signed in to change notification settings - Fork 149
Linked Image Mechanism: Cleanup! #843
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
| extension String { | ||
| /// String containing the NSTextAttachment Character | ||
| /// | ||
| static let textAttachment = String(UnicodeScalar(NSAttachmentCharacter)!) |
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.
Loved this little touch!
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.
I absolutely LOVE 'extensible enums' (that's this trick's name!)
|
|
||
| /// Verifies that `onlyChildr` returns the receiver's only child, if it's type matches with the specified one. | ||
| /// | ||
| func testOnlyChildReturnsSingleChildrenIfItRepresentsAnImage() { |
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 to have this tests on.
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.
Thank you sir!
SergioEstevao
left a comment
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 work here!
| } | ||
|
|
||
|
|
||
| /// Returns the ElementNode instance, whenever there's a *single* children, of the specified nodeType (or nil otherwise). |
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.
As "children" is the plural form, we should change to "child" here and in the lines below.
| /// If true, returns the '.img' node. | ||
|
|
||
|
|
||
| /// Whenever the `element`'s nodeType is `a` (link!), and there's a single children of the `.img` type, this method will return the |
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.
/s/children/child
| } | ||
|
|
||
|
|
||
| /// Verifies that `onlyChildr` returns the receiver's only child, if it's type matches with the specified one. |
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.
/s/onlyChildr/onlyChild
Want to avoid flooding the PR but search for other occurrences below.
| guard children.count == 1, | ||
| let onlyChild = children.first as? ElementNode, | ||
| onlyChild.isNodeType(type) | ||
| else { |
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.
Closing { goes in the same line as the declaration preceding it.
From https://github.com/wordpress-mobile/swift-style-guide#braces:
Opening braces should be preceded by a single space and on the same line as the declaration. The exception to this rule is when enclosed within parentheses: no preceding space is required.
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.
Our guidelines don't fully apply to this statement, because the guard clause has multiple lines / conditions.
Moving the else to the preceding line, would have the sad effect of forcing us to further increase the indentation level of the snippet that goes inside the else.
IMO this way we truly improve readability, and avoid increasing indentation.
I'll submit a formal request to add this to our guideline!
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.
I still think this looks very inconsistent with how we format the rest of our code, as we don't separate else statements from preceding declarations anywhere else.
The fact that auto-indent adds an extra tab should not affect how we format the code.
That said, as this won't affect the logic in the code, we can merge as it is.
| /// | ||
| /// - Returns: the requested children (if it's the only children in the collection, and if the type matches), or nil otherwise. | ||
| /// | ||
| func onlyChild(ofType type: StandardElementType) -> ElementNode? { |
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.
In order to aim for single-responsibility would you mind splitting this method into two steps (retrieval, filtering)?
This'd help ensure our methods are easier to compose, and also easier to read and understand.
Example:
/// This one returns first child found, if it's the only one.
///
func onlyChild() -> ElementNode? {
guard children.count == 1 else {
return nil
}
return children.first as? ElementNode
}
/// This one returns the first child found, if it's the only one and it matches the specified type.
///
func onlyChild(ofType type: StandardElementType) -> ElementNode? {
guard let child = onlyChild(),
child.isNodeType(type) else {
return nil
}
return child
}
diegoreymendez
left a comment
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.
Just one more missing "children" replacement, but otherwise approved.
Nice work.
| /// | ||
| /// - Parameter type: Type of the 'single child' node to be retrieved. | ||
| /// | ||
| /// - Returns: the requested children (if it's the only children in the collection, and if the type matches), or nil otherwise. |
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.
/s/children/child
|
Thank you both! |
Details:
This PR introduces no new functionality. We're:
textAttachmentconstant over to a String extension, for convenienceTo test:
<a href="www.wordpress.com"><img src="www.something.com/img"></a>Needs Review: @diegoreymendez
Thanks in advance!