rrrene / credo

A static code analysis tool for the Elixir language with a focus on code consistency and teaching.
http://credo-ci.org/
MIT License
4.91k stars 414 forks source link

`UnusedKeywordOperation` check should ignore `Keyword.validate!/2` #1128

Closed cgrothaus closed 3 months ago

cgrothaus commented 4 months ago

Environment

What were you trying to do?

Use Keyword.validate!/2, like in the following example:

defmodule Example do
  def function(arg1, opts \\ []) do
    # credo warns about the following line:
    Keyword.validate!(opts, [:base_url, :meta, :receive_timeout])

    # just some random code:
    base_url = Keyword.get(opts, :base_url) || ""
    arg1 <> base_url
  end
end

Expected outcome

No Credo warnings.

Actual outcome

Credo warns about unused return values for Keyword functions:

Checking 1324 source files (this might take a while) ...

  Warnings - please take a look                                                                                                                                                                                                                                    
┃ 
┃ [W] ↗ There should be no unused return values for Keyword functions.
┃       lib/example.ex:4:5 #(Example.function)

But for Keyword.validate!/2, we really do not need to use the return value.

rrrene commented 4 months ago

Thx for reporting! :+1:

rrrene commented 4 months ago

Thanks for reporting this 😀 It is now fixed on master.

You can try this by setting the Credo dep to

{:credo, github: "rrrene/credo"}

Please report back if your issue is solved! 👍

cgrothaus commented 4 months ago

Solved 🥳 ! Thanks for reacting so insanely fast 🏎️ .

rrrene commented 3 months ago

This is live in v1.7.6 🎉