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