zf

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

unused_regex_operation.ex (1076B)


      1 defmodule Credo.Check.Warning.UnusedRegexOperation do
      2   use Credo.Check,
      3     base_priority: :high,
      4     explanations: [
      5       check: """
      6       The result of a call to the Regex module's functions has to be used.
      7 
      8       While this is correct ...
      9 
     10           def extract_username_and_salute(regex, string) do
     11             [string] = Regex.run(regex, string)
     12 
     13             "Hi #\{string}"
     14           end
     15 
     16       ... we forgot to save the downcased username in this example:
     17 
     18           def extract_username_and_salute(regex, string) do
     19             Regex.run(regex, string)
     20 
     21             "Hi #\{string}"
     22           end
     23 
     24       Regex 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 :Regex
     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