-
Notifications
You must be signed in to change notification settings - Fork 414
/
unused_keyword_operation.ex
49 lines (37 loc) · 1.16 KB
/
unused_keyword_operation.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
defmodule Credo.Check.Warning.UnusedKeywordOperation do
use Credo.Check,
base_priority: :high,
explanations: [
check: """
The result of a call to the Keyword module's functions has to be used.
While this is correct ...
def clean_and_verify_options!(keywords) do
keywords = Keyword.delete(keywords, :debug)
if Enum.length(keywords) == 0, do: raise "OMG!!!1"
keywords
end
... we forgot to save the result in this example:
def clean_and_verify_options!(keywords) do
Keyword.delete(keywords, :debug)
if Enum.length(keywords) == 0, do: raise "OMG!!!1"
keywords
end
Keyword operations never work on the variable you pass in, but return a new
variable which has to be used somehow.
"""
]
alias Credo.Check.Warning.UnusedOperation
@checked_module :Keyword
@funs_with_return_value nil
@doc false
@impl true
def run(%SourceFile{} = source_file, params) do
UnusedOperation.run(
source_file,
params,
@checked_module,
@funs_with_return_value,
&format_issue/2
)
end
end