Skip to content
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

Merged
merged 31 commits into from
Aug 15, 2017

Conversation

Antondomashnev
Copy link
Contributor

@Antondomashnev Antondomashnev commented Jul 16, 2017

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.

@Antondomashnev Antondomashnev changed the title Additional filters for String; Additional filters for String; [WIP] Jul 16, 2017
@djbe
Copy link
Member

djbe commented Jul 16, 2017

First thing that pops in my mind: We already have a first letter uppercase filter, we call it titlecase (link)

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 djbe added this to the Nice To Have milestone Jul 16, 2017
@Antondomashnev
Copy link
Contributor Author

@djbe that's right. I've noticed it as well 😄
Another concern after small fixes - the Swiflint has warnings because of Strings filters files length and big tuple in Environment.swift. That is the reason of CI fail.

@Antondomashnev Antondomashnev changed the title Additional filters for String; [WIP] Additional filters for String; Jul 16, 2017
@Antondomashnev
Copy link
Contributor Author

@djbe any chance you can check it soon? 😄

Copy link
Member

@Liquidsoul Liquidsoul left a 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
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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 {
Copy link
Member

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.

Copy link
Contributor Author

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

@Liquidsoul
Copy link
Member

After testing the code locally, it may not be necessary to address the large_tuple issue. The build seems to pass with just the file_length fix.
BTW, I do not think that swiftlint should show a warning here because this is about a closure, not a tuple 🤔

@Liquidsoul
Copy link
Member

I have submitted a PR to fix the large_tuple issue in Swiftlint realm/SwiftLint#1725
We will see how it goes 😄

@Antondomashnev
Copy link
Contributor Author

In f1af687 the swiftlint rule to check the file length was disabled 😄

@Antondomashnev
Copy link
Contributor Author

I have submitted a PR to fix the large_tuple issue in Swiftlint realm/SwiftLint#1725

Awesome, thanks for taking care of it 👍

@Liquidsoul
Copy link
Member

Liquidsoul commented Jul 29, 2017

Thank you a lot for all this work! 👏

However, I would suggest to split the changes into several PRs, particularly 595e3aa and ed4477e1.
I think that ed4477e1 is kind of related to #56 and 595e3aa involves a lot of changes that are not related to adding the new filters here.

@Liquidsoul
Copy link
Member

Sorry for my previous comment, I think looking at just the commits individually made me see something that was not here 😅

@Antondomashnev
Copy link
Contributor Author

@djbe I've renamed titlecase into upperFirstLetter in f3d66af.

@@ -257,7 +257,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if [[ ! $CI ]]; then\n rake lint:code\n rake lint:tests\nfi";
shellScript = "";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this removed?

Copy link
Contributor Author

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

@@ -114,7 +114,7 @@ https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift
| `42hello` | `_42hello` |
| `some$URL` | `Some_URL` |

## Filter: `titlecase`
## Filter: `upperFirstLetter`
Copy link
Member

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.

Copy link
Contributor Author

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

@@ -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? {
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 81aefea

@@ -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)
Copy link
Member

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.

Copy link
Contributor Author

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

@djbe
Copy link
Member

djbe commented Jul 30, 2017

Nice! We might want to add an entry to the Migration Guide for the titlecase change. The next version should be 2.1.0.

@AliSoftware AliSoftware modified the milestones: 2.1.0, Nice To Have Aug 13, 2017
@AliSoftware
Copy link
Contributor

I think we can integrate that in the next 2.1.0 👍

@AliSoftware
Copy link
Contributor

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!

@Antondomashnev
Copy link
Contributor Author

@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 🚀

@Antondomashnev
Copy link
Contributor Author

@AliSoftware @djbe @Liquidsoul may I rebase it into master as it's approved?

@AliSoftware
Copy link
Contributor

Would be perfect 👍

@Antondomashnev
Copy link
Contributor Author

@AliSoftware apparently...

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"
Copy link
Contributor

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 ///?

Copy link
Contributor Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@Liquidsoul
Copy link
Member

@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 😉

@Liquidsoul
Copy link
Member

In other words, you need to do your rebase manually 😅

@AliSoftware
Copy link
Contributor

@Antondomashnev I've added you as contributor to the SwiftGenKit repo hopefully it will give you the rights you need

@AliSoftware
Copy link
Contributor

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 😉

@AliSoftware AliSoftware merged commit 00882eb into SwiftGen:master Aug 15, 2017
@Antondomashnev
Copy link
Contributor Author

@Liquidsoul thanks for the clarification 👍

@Antondomashnev Antondomashnev deleted the additional_filters branch August 15, 2017 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants