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

Convert custom_associations to array of symbols #356

Merged
merged 1 commit into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/packwerk/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Copy link
Member Author

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 🤔

Copy link
Member Author

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.

@parallel = T.let(configs.key?("parallel") ? configs["parallel"] : true, T::Boolean)
@cache_enabled = T.let(configs.key?("cache") ? configs["cache"] : false, T::Boolean)
@cache_directory = T.let(Pathname.new(configs["cache_directory"] || "tmp/cache/packwerk"), Pathname)
Expand Down
2 changes: 1 addition & 1 deletion test/unit/packwerk/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

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?

assert_equal [:custom_association], configuration.custom_associations
end

test ".from_path falls back to some default config when no existing config exists" do
Expand Down