Skip to content

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

@cgrothaus

Description

@cgrothaus

Environment

  • Credo version: 1.7.5-ref.main.a6568e1ca
  • Erlang/Elixir version: Erlang/OTP 26 [erts-14.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]; Elixir 1.16.1 (compiled with Erlang/OTP 26)
  • Operating system: mac OS

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.

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