zf

zenflows testing
git clone https://s.sonu.ch/~srfsh/zf.git
Log | Files | Refs | Submodules | README | LICENSE

unused_tuple_operation.ex (1131B)


      1 defmodule Credo.Check.Warning.UnusedTupleOperation do
      2   use Credo.Check,
      3     base_priority: :high,
      4     explanations: [
      5       check: """
      6       The result of a call to the Tuple module's functions has to be used.
      7 
      8       While this is correct ...
      9 
     10           def remove_magic_item!(tuple) do
     11             tuple = Tuple.delete_at(tuple, 0)
     12 
     13             if Enum.length(tuple) == 0, do: raise "OMG!!!1"
     14 
     15             tuple
     16           end
     17 
     18       ... we forgot to save the result in this example:
     19 
     20           def remove_magic_item!(tuple) do
     21             Tuple.delete_at(tuple, 0)
     22 
     23             if Enum.length(tuple) == 0, do: raise "OMG!!!1"
     24 
     25             tuple
     26           end
     27 
     28       Tuple 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 :Tuple
     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