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