zf

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

params.ex (2300B)


      1 defmodule Credo.Check.Params do
      2   @moduledoc """
      3   This module provides functions for handling parameters ("params") given to
      4   checks through `.credo.exs` (i.e. the `Credo.ConfigFile`).
      5   """
      6 
      7   @doc """
      8   Returns the given `field`'s `params` value.
      9 
     10   Example:
     11 
     12       defmodule SamepleCheck do
     13         def param_defaults do
     14           [foo: "bar"]
     15         end
     16       end
     17 
     18       iex> Credo.Check.Params.get([], :foo, SamepleCheck)
     19       "bar"
     20       iex> Credo.Check.Params.get([foo: "baz"], :foo, SamepleCheck)
     21       "baz"
     22   """
     23   def get(params, field, check_mod)
     24 
     25   # this one is deprecated
     26   def get(params, field, keywords) when is_list(keywords) do
     27     case params[field] do
     28       nil ->
     29         keywords[field]
     30 
     31       val ->
     32         val
     33     end
     34   end
     35 
     36   def get(params, field, check_mod) do
     37     case params[field] do
     38       nil ->
     39         check_mod.param_defaults[field]
     40 
     41       val ->
     42         val
     43     end
     44   end
     45 
     46   @doc false
     47   def get_rerun_files_that_changed(params) do
     48     List.wrap(params[:__rerun_files_that_changed__])
     49   end
     50 
     51   @doc false
     52   def put_rerun_files_that_changed(params, files_that_changed) do
     53     Keyword.put(params, :__rerun_files_that_changed__, files_that_changed)
     54   end
     55 
     56   @doc false
     57   def builtin_param_names do
     58     [
     59       :category,
     60       :__category__,
     61       :exit_status,
     62       :__exit_status__,
     63       :files,
     64       :__files__,
     65       :priority,
     66       :__priority__,
     67       :tags,
     68       :__tags__
     69     ]
     70   end
     71 
     72   @doc false
     73   def category(params, check_mod) do
     74     params[:__category__] || params[:category] || check_mod.category
     75   end
     76 
     77   @doc false
     78   def exit_status(params, check_mod) do
     79     params[:__exit_status__] || params[:exit_status] || check_mod.exit_status
     80   end
     81 
     82   @doc false
     83   def files_excluded(params, check_mod) do
     84     files = get(params, :__files__, check_mod) || get(params, :files, check_mod)
     85 
     86     List.wrap(files[:excluded])
     87   end
     88 
     89   @doc false
     90   def files_included(params, check_mod) do
     91     files = get(params, :__files__, check_mod) || get(params, :files, check_mod)
     92 
     93     List.wrap(files[:included])
     94   end
     95 
     96   @doc false
     97   def priority(params, check_mod) do
     98     params[:__priority__] || params[:priority] || check_mod.base_priority
     99   end
    100 
    101   @doc false
    102   def tags(params, check_mod) do
    103     params[:__tags__] || params[:tags] || check_mod.tags
    104   end
    105 end