Skip to content

[Question] What to do about used/unused variable warnings? #31

@coladarci

Description

@coladarci

Forgive me for using this as a venue to get a recommendation, but I'm having a really hard time even forming my question in other venues, so I thought I'd try it out here since this library is what spurred this question.

My goal here is to explore adding permission checks to my context functions.

@decorate permit(:create_thing)
def create_thing(_user, params), do:
   %Thing{} |> Thing.changset(params) |> Repo.insert()

I have setup permit to use the first argument provided to the decorated function (the user):

def permit(action, body, %{args: [user, _params]}) do
   with :ok -> Permissions.can(user, action) do
     unquote(body)
   end
end

Note that in the above use-case, the user is actually only used in the decorated code, NOT the function being decorated. This confuses the compiler and gives warnings (if it's underscored, I'm told that it's being used even though it's underscored. If it's NOT underscored, I get warnings saying it's unused).

I have to note that this entire thing smells bad because my best case scenario here is that a seemingly unused arg is actually being used (or vice-versa). This makes me seriously question my API choices, but I think I'm onto a very powerful use of this library.

SO, my question is:

  1. Is what I'm running into something that feels like a bug somewhere? Is it a common issue?
  2. Seeing what I'm attempting to accomplish, am I missing anything obvious that might be a better API approach?

Thanks for a great library - appreciate all the work that went into it!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions