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

add coerce_empty_to_nil config for string conversion #65

Merged

Conversation

leifg
Copy link
Contributor

@leifg leifg commented Jul 17, 2022

After clarifying in #58 seems to be a good config flag for coercing empty strings into nil.

Closes #58.

@codecov
Copy link

codecov bot commented Jul 21, 2022

Codecov Report

Merging #65 (12a93ac) into master (89e2d8d) will increase coverage by 0.04%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master      #65      +/-   ##
==========================================
+ Coverage   99.22%   99.26%   +0.04%     
==========================================
  Files           6        6              
  Lines         386      409      +23     
==========================================
+ Hits          383      406      +23     
  Misses          3        3              
Impacted Files Coverage Δ
lib/sorbet-coerce/converter.rb 97.50% <100.00%> (+0.13%) ⬆️
spec/coerce_spec.rb 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us.

Copy link
Contributor

@mattxwang mattxwang left a comment

Choose a reason for hiding this comment

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

Thank you for the quick turnaround and your contribution @leifg! This seems pretty great to me, and I've had a chance to test this locally (as well as on CI - thanks for submitting the PR to resolve the issues with ruby 3+).

What are your thoughts on also adding a global configuration parameter, similar to TypeCoerce::Configuration.raise_coercion_error? No need to do this if you don't think it's necessary (for example, I'm not sure if it's relevant in your use-case of request parsing).


As an aside, I'll probably publish a new release of the gem after we merge this in. Hopefully you'll have a chance to test this soon!

@mattxwang mattxwang changed the title add empty string conversion parameter add coerce_empty_to_nil config for string conversion Jul 22, 2022
@leifg
Copy link
Contributor Author

leifg commented Jul 22, 2022

What are your thoughts on also adding a global configuration parameter, similar to TypeCoerce::Configuration.raise_coercion_error? No need to do this if you don't think it's necessary (for example, I'm not sure if it's relevant in your use-case of request parsing).

For me personally I don't see a use case. In addition: making something like a global flag could cause unwanted errors because you would get instances of TypeError where an empty string is fine.

@mattxwang
Copy link
Contributor

For me personally I don't see a use case. In addition: making something like a global flag could cause unwanted errors because you would get instances of TypeError where an empty string is fine.

Sounds good, just wanted to check in. Thanks again for your contribution, much appreciated!

@mattxwang mattxwang merged commit 402257c into chanzuckerberg:master Jul 22, 2022
@leifg
Copy link
Contributor Author

leifg commented Jul 22, 2022

Sounds good, just wanted to check in. Thanks again for your contribution, much appreciated!

Of course! Always happy to help out.

@leifg leifg deleted the add-empty-string-conversion-parameter branch July 22, 2022 18:15
jez pushed a commit to sorbet/sorbet-typed that referenced this pull request Jul 25, 2022
…` option) (#396)

* Updates `sorbet-coerce` with new `coerce_empty_to_nil` option

See: chanzuckerberg/sorbet-coerce#65
and release notes: https://github.com/chanzuckerberg/sorbet-coerce/releases/tag/v0.6.0

* renames folder to be a simple constraint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Question] Accept PR for config flag on how to deal with empty strings
2 participants