-
Notifications
You must be signed in to change notification settings - Fork 58
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
Additional filters for String; #54
Additional filters for String; #54
Conversation
First thing that pops in my mind: We already have a first letter uppercase filter, we call it I'll take a look at the other filters during the next week. Edit: I see you've already removed the upperFirstLetter while I was writing this 😄 |
@djbe that's right. I've noticed it as well 😄 |
@djbe any chance you can check it soon? 😄 |
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.
There are still some upperFirstLetter
references here which makes the build fails 😉
About the swiftlint errors:
file_length
: maybe we could silenced it by adding the swiftlint annotation// swiftlint:disable file_length
and plan to split the tests into several files in another PR?large_tuple
: if there cannot be another implementation without it, we need to silence the error just for the line
CHANGELOG.md
Outdated
@@ -36,6 +36,10 @@ Due to the removal of legacy code, there are a few breaking changes in this new | |||
|
|||
### New Features | |||
|
|||
* Added the `contains`, `replace`, `hasPrefix`, `hasSuffix`, `upperFirstLetter`, `lowerFirstLetter` filters for strings |
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.
You need to remove upperFirstLetter
here.
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, thanks. It's removed in cbfbce5
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.
It seems that you missed the CHANGELOG.md
change in the commit. It's not in it 😉
@@ -285,3 +285,215 @@ extension StringFiltersTests { | |||
} | |||
} | |||
} | |||
|
|||
extension StringFiltersTests { | |||
func testUpperFirstLetter() throws { |
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.
Because upperFirstLetter
was removed you need to remove this.
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.
Thanks, deletion is in cbfbce5
After testing the code locally, it may not be necessary to address the |
I have submitted a PR to fix the |
In f1af687 the swiftlint rule to check the file length was disabled 😄 |
Awesome, thanks for taking care of it 👍 |
6035c1e
to
ed477e1
Compare
Sorry for my previous comment, I think looking at just the commits individually made me see something that was not here 😅 |
@@ -257,7 +257,7 @@ | |||
); | |||
runOnlyForDeploymentPostprocessing = 0; | |||
shellPath = /bin/sh; | |||
shellScript = "if [[ ! $CI ]]; then\n rake lint:code\n rake lint:tests\nfi"; | |||
shellScript = ""; |
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.
Why was this removed?
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.
By mistake. Rollback in fbd84a0
Documentation/filters-strings.md
Outdated
@@ -114,7 +114,7 @@ https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift | |||
| `42hello` | `_42hello` | | |||
| `some$URL` | `Some_URL` | | |||
|
|||
## Filter: `titlecase` | |||
## Filter: `upperFirstLetter` |
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'd add a note here that titlecase
still exists.
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.
Makes sense. Added in 84379ce
Sources/Filters+Strings.swift
Outdated
@@ -60,8 +88,21 @@ extension Filters { | |||
let transformed = String(scalars[start..<idx]).lowercased() + String(scalars[idx..<scalars.endIndex]) | |||
return transformed | |||
} | |||
|
|||
|
|||
/// Deprecated in favor of `upperFirstLetter` | |||
static func titlecase(_ value: Any?) throws -> Any? { |
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 remove this function, and point the registerFilter
call to the function below.
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.
Done in 81aefea
Sources/Environment.swift
Outdated
@@ -20,6 +20,12 @@ public extension Extension { | |||
registerFilter("snakeToCamelCase", filter: Filters.Strings.snakeToCamelCase) | |||
registerFilter("swiftIdentifier", filter: Filters.Strings.swiftIdentifier) | |||
registerFilter("titlecase", filter: Filters.Strings.titlecase) |
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.
Point this to the new upperFirstLetter
function.
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.
Yep, good point. See 81aefea
Nice! We might want to add an entry to the Migration Guide for the titlecase change. The next version should be 2.1.0. |
I think we can integrate that in the next 2.1.0 👍 |
Btw @Antondomashnev to thank you for your work and for taking time to improve the lib, I've invited you to join SwiftGen's GitHub organization's "CoreContributors" team 😃 No pressure to accept nor any obligation in that! It will just give you the ability to help triage issues or push directly branches to the repo (instead of your fork)… in case you want to contribute again in the future 😉 For more information, read the COMMUNITY.md and CONTRIBUTING.md documents, and if you have any questions don't hesitate to reach out! |
@AliSoftware thanks, I'd try to be any help, since we're actively using some SwiftGen projects in Sourcery and I also use some in my OSS 🚀 |
@AliSoftware @djbe @Liquidsoul may I rebase it into |
Would be perfect 👍 |
@AliSoftware apparently... |
Sources/Filters+Strings.swift
Outdated
static func swiftIdentifier(_ value: Any?) throws -> Any? { | ||
guard let value = value as? String else { throw Filters.Error.invalidInputType } | ||
return StencilSwiftKit.swiftIdentifier(from: value, replaceWithUnderscores: true) | ||
} | ||
|
||
/* Lowers the first letter of the string | ||
* e.g. "People picker" gives "people picker", "Sports Stats" gives "sports Stats" |
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.
Why the inconsistency of comments style compared to the rest which properly use ///
?
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.
No reason 😄 it's updated in 129ab6d
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.
👍
@Antondomashnev you've been given push access to the repository (you can push your branches to the repo and you can manage the issues) but push to ˋmaster` must be done by the Core team 😉 |
In other words, you need to do your rebase manually 😅 |
@Antondomashnev I've added you as contributor to the SwiftGenKit repo hopefully it will give you the rights you need |
Codebeat isn't gonna go green because we increased the size of the filters file too much. I'm gonna merge it anyway but a new PR on top of this, splitting the filters file in multiple Swift files, would be appreciated 😉 |
@Liquidsoul thanks for the clarification 👍 |
This PR reflects the issue in Sourcery. First of all, all credits goes to the filter's creators: @ilyapuchka, @krzysztofzablocki, @yageek and @sibljon.
I have some concern of better way to implement helper functions to register filters with one and two arguments, at the moment it's just a copy paste from Sourcery repo.