unused_keyword_operation.ex (1188B)
1 defmodule Credo.Check.Warning.UnusedKeywordOperation do 2 use Credo.Check, 3 base_priority: :high, 4 explanations: [ 5 check: """ 6 The result of a call to the Keyword module's functions has to be used. 7 8 While this is correct ... 9 10 def clean_and_verify_options!(keywords) do 11 keywords = Keyword.delete(keywords, :debug) 12 13 if Enum.length(keywords) == 0, do: raise "OMG!!!1" 14 15 keywords 16 end 17 18 ... we forgot to save the result in this example: 19 20 def clean_and_verify_options!(keywords) do 21 Keyword.delete(keywords, :debug) 22 23 if Enum.length(keywords) == 0, do: raise "OMG!!!1" 24 25 keywords 26 end 27 28 Keyword operations never work on the variable you pass in, but return a new 29 variable which has to be used somehow. 30 """ 31 ] 32 33 alias Credo.Check.Warning.UnusedOperation 34 35 @checked_module :Keyword 36 @funs_with_return_value nil 37 38 @doc false 39 @impl true 40 def run(%SourceFile{} = source_file, params) do 41 UnusedOperation.run( 42 source_file, 43 params, 44 @checked_module, 45 @funs_with_return_value, 46 &format_issue/2 47 ) 48 end 49 end