Skip to content

Commit 94b2fab

Browse files
committed
Handle no-specify, no-ex-check and no-gradualizer-check options
1 parent 6d4f06b commit 94b2fab

File tree

3 files changed

+52
-6
lines changed

3 files changed

+52
-6
lines changed

lib/gradient.ex

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ defmodule Gradient do
55
Options:
66
- `app_path` - Path to the app that contains file with code (for umbrella apps).
77
- `code_path` - Path to a file with code (e.g. when beam was compiled without project).
8+
- `no_gradualizer_check` - Skip Gradualizer checks if true.
9+
- `no_ex_check` - Skip Elixir checks if true.
10+
- `no_specify` - Skip AST specifying if true.
811
"""
912

1013
alias Gradient.ElixirFileUtils
@@ -21,12 +24,9 @@ defmodule Gradient do
2124
opts = Keyword.put(opts, :return_errors, true)
2225

2326
with {:ok, forms} <- ElixirFileUtils.get_forms(file) do
24-
forms =
25-
forms
26-
|> put_code_path(opts)
27-
|> AstSpecifier.specify()
27+
forms = maybe_specify_forms(forms, opts)
2828

29-
case ElixirChecker.check(forms, opts) ++ :gradualizer.type_check_forms(forms, opts) do
29+
case maybe_gradient_check(forms, opts) ++ maybe_gradualizer_check(forms, opts) do
3030
[] ->
3131
:ok
3232

@@ -42,6 +42,32 @@ defmodule Gradient do
4242
end
4343
end
4444

45+
defp maybe_gradualizer_check(forms, opts) do
46+
unless opts[:no_gradualizer_check] do
47+
:gradualizer.type_check_forms(forms, opts)
48+
else
49+
[]
50+
end
51+
end
52+
53+
defp maybe_gradient_check(forms, opts) do
54+
unless opts[:no_ex_check] do
55+
ElixirChecker.check(forms, opts)
56+
else
57+
[]
58+
end
59+
end
60+
61+
defp maybe_specify_forms(forms, opts) do
62+
unless opts[:no_specify] do
63+
forms
64+
|> put_code_path(opts)
65+
|> AstSpecifier.specify()
66+
else
67+
forms
68+
end
69+
end
70+
4571
defp put_code_path(forms, opts) do
4672
case opts[:code_path] do
4773
nil ->

lib/gradient/doublespec.ex

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
defmodule Doublespec do
2+
@spec convert(integer()) :: float()
3+
@spec convert(atom()) :: binary()
4+
def convert(int) when is_integer(int), do: int / 1
5+
def convert(atom) when is_atom(atom), do: to_string(atom)
6+
7+
@spec convert(atom()) :: binary()
8+
def last_two(list) do
9+
[last, penultimate | _tail] = Enum.reverse(list)
10+
[penultimate, last]
11+
end
12+
13+
@spec last_two(atom()) :: atom()
14+
def last_three(:ok) do
15+
:ok
16+
end
17+
end

lib/mix/tasks/gradient.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ defmodule Mix.Tasks.Gradient do
88
* `--no-compile` - do not compile even if needed
99
* `--no-ex-check` - do not perform checks specyfic for Elixir
1010
(from ElixirChecker module)
11-
* `--no-gradualizer-check` - do not perform Gradualizer checks
11+
* `--no-gradualizer-check` - do not perform the Gradualizer checks
12+
* `--no-specify` - do not specify missing lines in AST what can
13+
result in less precise error messages
1214
15+
* `--no-deps` - do not import dependencies to the Gradualizer
1316
* `--stop_on_first_error` - stop type checking at the first error
1417
* `--infer` - infer type information from literals and other language
1518
constructs,

0 commit comments

Comments
 (0)