zf

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

unused_file_operation.ex (1175B)


      1 defmodule Credo.Check.Warning.UnusedFileOperation do
      2   use Credo.Check,
      3     base_priority: :high,
      4     explanations: [
      5       check: """
      6       The result of a call to the File module's functions has to be used.
      7 
      8       While this is correct ...
      9 
     10           def read_from_cwd(filename) do
     11             # TODO: use Path.join/2
     12             filename = File.cwd!() <> "/" <> filename
     13 
     14             File.read(filename)
     15           end
     16 
     17       ... we forgot to save the result in this example:
     18 
     19           def read_from_cwd(filename) do
     20             File.cwd!() <> "/" <> filename
     21 
     22             File.read(filename)
     23           end
     24 
     25       Since Elixir variables are immutable, many File operations don't work on the
     26       variable you pass in, but return a new variable which has to be used somehow.
     27       """
     28     ]
     29 
     30   alias Credo.Check.Warning.UnusedOperation
     31 
     32   @checked_module :File
     33   @funs_with_return_value ~w(cwd cwd! dir? exists? read read! regular? stat stat!)a
     34 
     35   @doc false
     36   @impl true
     37   def run(%SourceFile{} = source_file, params) do
     38     UnusedOperation.run(
     39       source_file,
     40       params,
     41       @checked_module,
     42       @funs_with_return_value,
     43       &format_issue/2
     44     )
     45   end
     46 end