ucbi / uniform

Write less boilerplate and reuse more code in your portfolio of Elixir apps
https://hex.pm/packages/uniform
Apache License 2.0
33 stars 1 forks source link

Stop requiring constant prefix for `only`, `except`, and `app_lib_except`? #38

Closed paulstatezny closed 2 years ago

paulstatezny commented 2 years ago

Current Behavior

As you can see in the Setting up a Phoenix project guide, every string you pass to the only and except options as well as the app_lib_except callback will always start with lib/my_app_or_lib where my_app_or_lib is whatever the directory in lib is.

For example:

def app_lib_except(app) do
  [
    "lib/#{app.name.underscore}/hidden_file.ex",
    "lib/#{app.name.underscore}/foo/bar/another_hidden_file.ex"
  ]
end
lib :foo_bar do
  only [
    "lib/foo_bar/some/path/in/here.ex",
    "lib/foo_bar/another/path/in/this/lib.ex"
  ]
end
lib :another_lib do
  except [
    "lib/another_lib/schemas/post.ex",
    "lib/another_lib/whatever.ex"
  ]
end

It's pretty redundant.

Suggested Behavior

Would it be nicer DX if we auto-prepended the lib/foo/ behind the scenes? So that the user would enter this instead:

def app_lib_except(app) do
  [
    "hidden_file.ex",
    "foo/bar/another_hidden_file.ex"
  ]
end
lib :foo_bar do
  only [
    "some/path/in/here.ex",
    "another/path/in/this/lib.ex"
  ]
end
lib :another_lib do
  except [
    "schemas/post.ex",
    "whatever.ex"
  ]
end
paulstatezny commented 2 years ago

Actually, there's a complicating factor.

The files that only, except, and app_lib_except filter are both the ones in lib/foo and test/foo.

So if the user wasn't supposed to specify the lib/foo/ prefix, how would they differentiate between a path in lib and an identical path in test?

It's an edge case for sure since most files in lib will typically end in .ex and most files in test will end in _test.exs. But what if you happened to have something like this:

+ lib
  + my_app
    - authorization.ex
+ test
  + my_app
    - authorization.ex

Imagine that the file in lib performs authorization tasks for the app, and the file in test includes test setup code for the app.

Perhaps this would be even more peculiar because the modules in these files would have a naming conflict if the developer followed typical community conventions. (They'd both by called MyApp.Authorization.)

But it still feels a bit too ambiguous for me from a clarity standpoint.

Imagine a structure like this:

+ lib
  + my_lib
    - auth.ex
+ test
  + my_lib
    - auth_helper.ex

With the change suggested by this issue, the user would say:

lib :my_lib do
  only [
    "auth.ex",
    "auth_helper.ex"
  ]
end

By looking just at the only invocation, it's not fully clear whether auth.ex is in lib or test.

For this reason, we should probably keep the behavior as-is.