-
Notifications
You must be signed in to change notification settings - Fork 113
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
Convert custom_associations
to array of symbols
#356
Convert custom_associations
to array of symbols
#356
Conversation
5935590
to
8ef194d
Compare
8ef194d
to
066bd48
Compare
@@ -75,7 +75,7 @@ def initialize(configs = {}, config_path: nil) | |||
root = config_path ? File.dirname(config_path) : "." | |||
@root_path = T.let(File.expand_path(root), String) | |||
@package_paths = T.let(configs["package_paths"] || "**/", T.any(String, T::Array[String])) | |||
@custom_associations = T.let(configs["custom_associations"] || [], T::Array[Symbol]) | |||
@custom_associations = T.let((configs["custom_associations"] || []).map(&:to_sym), T::Array[Symbol]) |
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'm confused why Sorbet wasn't blowing up on this since the array wasn't an array of symbols 🤔
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.
Ah configs
is a hash with untyped values.
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 too am surprised this has not been a problem already.
Looks like the packwerk.yml
template would have given wrong instructions?
packwerk/lib/packwerk/generators/templates/packwerk.yml.erb
Lines 15 to 17 in 95caea0
# List of custom associations, if any | |
# custom_associations: | |
# - "cache_belongs_to" |
Fix looks good to me! 👍🏻
@@ -42,7 +42,7 @@ class ConfigurationTest < Minitest::Test | |||
assert_equal ["{exclude_dir,bin,tmp}/**/*"], configuration.exclude | |||
assert_equal app_dir, configuration.root_path | |||
assert_equal "**/*/", configuration.package_paths | |||
assert_equal ["custom_association"], configuration.custom_associations |
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.
yet if you set an array of strings for custom_associations then Packwerk will simply ignore them without any error.
So this test was "right", but testing an invalid scenario?
What are you trying to accomplish?
Having symbols in a yaml array is less natural than an array of strings, yet if you set an array of strings for
custom_associations
then Packwerk will simply ignore them without any error.And actually, the example config itself has an array of strings:
packwerk/lib/packwerk/generators/templates/packwerk.yml.erb
Lines 15 to 17 in 066bd48
What approach did you choose and why?
Just convert them to symbols when assigning from yaml.
What should reviewers focus on?
Why wasn't Sorbet blowing up on this? There's a
T.let
assigning to an array of symbols, yet it was assigning an array of Strings, that should be a problem. 🤔Type of Change
Additional Release Notes
Include any notes here to include in the release description. For example, if you selected "breaking change" above, leave notes on how users can transition to this version.
If no additional notes are necessary, delete this section or leave it unchanged.
Checklist