Skip to content

Commit 5919843

Browse files
authored
Merge pull request #57 from belltoy/fix/type-spec
Fix type spec
2 parents 0cdd103 + cdda7ff commit 5919843

15 files changed

+216
-161
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,6 @@ jobs:
7575
otp-version: ${{matrix.otp}}
7676
rebar3-version: '3.20.0'
7777
version-type: strict
78-
- run: rebar3 do ct -v -c, cover -v
78+
- run: rebar3 do xref, dialyzer, gradualizer, ct -v -c, cover -v
7979
env:
8080
TERM: xterm-color

include/eetcd.hrl

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
-type value() :: iodata().
1111
-type context() :: map().
1212
-type name() :: atom() | reference().
13+
-type new_context() :: atom() | reference() | context().
1314
-type eetcd_error() :: timeout|{grpc_error,grpc_status()}|{gun_down,any()}|{gun_conn_error,any()}|{gun_stream_error,any()}|eetcd_conn_unavailable.
1415
-type grpc_status() :: #{'grpc-status' => integer(), 'grpc-message' => binary()}.
1516

rebar.config

+15
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@
2828
{rebar3_eetcd_plugin, "0.3.2"}
2929
]}.
3030

31+
{project_plugins, [
32+
{gradualizer, {git, "https://github.com/josefs/Gradualizer.git", {branch, "master"}}}
33+
]}.
34+
35+
{gradualizer_opts, [
36+
{include, ["include"]},
37+
38+
%% Use exclude_modules instead of exclude, See:
39+
%% https://github.com/josefs/Gradualizer/issues/483
40+
{exclude_modules, [
41+
]},
42+
{color, always}
43+
]}.
44+
3145
{xref_checks, [
3246
undefined_function_calls,
3347
undefined_functions,
@@ -40,6 +54,7 @@
4054
{xref_ignores, [
4155
auth_pb,
4256
gogo_pb,
57+
health_pb,
4358
kv_pb,
4459
router_pb
4560
]}.

src/eetcd_auth.erl

+30-30
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
%%% </dd> </dl>
2727
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
2828
%%% @end
29-
-spec auth_enable(name()|context()) ->
29+
-spec auth_enable(new_context()) ->
3030
{ok,router_pb:'Etcd.AuthEnableResponse'()}|{error,eetcd_error()}.
3131
auth_enable(Context) ->
3232
eetcd_auth_gen:auth_enable(new(Context)).
@@ -45,7 +45,7 @@ auth_enable(Context) ->
4545
%%% </dd> </dl>
4646
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
4747
%%% @end
48-
-spec auth_disable(name()|context()) ->
48+
-spec auth_disable(new_context()) ->
4949
{ok,router_pb:'Etcd.AuthDisableResponse'()}|{error,eetcd_error()}.
5050
auth_disable(Context) ->
5151
eetcd_auth_gen:auth_disable(new(Context)).
@@ -64,7 +64,7 @@ auth_disable(Context) ->
6464
%%% </dd> </dl>
6565
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
6666
%%% @end
67-
-spec user_add(name()|context(), iodata(), iodata()) ->
67+
-spec user_add(new_context(), iodata(), iodata()) ->
6868
{ok,router_pb:'Etcd.AuthUserAddResponse'()}|{error,eetcd_error()}.
6969
user_add(Context, Name, Password) ->
7070
C1 = new(Context),
@@ -86,10 +86,10 @@ user_add(Context, Name, Password) ->
8686
%%% </dd> </dl>
8787
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
8888
%%% @end
89-
-spec user_add(name()|context(), iodata()) ->
89+
-spec user_add(new_context(), iodata()) ->
9090
{ok,router_pb:'Etcd.AuthUserAddResponse'()}|{error,eetcd_error()}.
9191
user_add(Context, Name) ->
92-
C1 = eetcd:new(Context),
92+
C1 = new(Context),
9393
C2 = maps:put(name, Name, C1),
9494
C3 = maps:put(options, #{no_password => true}, C2),
9595
eetcd_auth_gen:user_add(C3).
@@ -108,10 +108,10 @@ user_add(Context, Name) ->
108108
%%% </dd> </dl>
109109
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
110110
%%% @end
111-
-spec user_delete(name()|context(), iodata()) ->
111+
-spec user_delete(new_context(), iodata()) ->
112112
{ok,router_pb:'Etcd.AuthUserDeleteResponse'()}|{error,eetcd_error()}.
113113
user_delete(Context, Name) ->
114-
C1 = eetcd:new(Context),
114+
C1 = new(Context),
115115
C2 = maps:put(name, Name, C1),
116116
eetcd_auth_gen:user_delete(C2).
117117

@@ -129,10 +129,10 @@ user_delete(Context, Name) ->
129129
%%% </dd> </dl>
130130
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
131131
%%% @end
132-
-spec user_change_password(name()|context(), iodata(), iodata()) ->
132+
-spec user_change_password(new_context(), iodata(), iodata()) ->
133133
{ok,router_pb:'Etcd.AuthUserChangePasswordResponse'()}|{error,eetcd_error()}.
134134
user_change_password(Context, Name, Password) ->
135-
C1 = eetcd:new(Context),
135+
C1 = new(Context),
136136
C2 = maps:put(name, Name, C1),
137137
C3 = maps:put(password, Password, C2),
138138
eetcd_auth_gen:user_change_password(C3).
@@ -151,10 +151,10 @@ user_change_password(Context, Name, Password) ->
151151
%%% </dd> </dl>
152152
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
153153
%%% @end
154-
-spec user_grant_role(name()|context(), iodata(), iodata()) ->
154+
-spec user_grant_role(new_context(), iodata(), iodata()) ->
155155
{ok,router_pb:'Etcd.AuthUserGrantRoleResponse'()}|{error,eetcd_error()}.
156156
user_grant_role(Context, User, Role) ->
157-
C1 = eetcd:new(Context),
157+
C1 = new(Context),
158158
C2 = maps:put(user, User, C1),
159159
C3 = maps:put(role, Role, C2),
160160
eetcd_auth_gen:user_grant_role(C3).
@@ -173,10 +173,10 @@ user_grant_role(Context, User, Role) ->
173173
%%% </dd> </dl>
174174
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
175175
%%% @end
176-
-spec user_get(name()|context(), iodata()) ->
176+
-spec user_get(new_context(), iodata()) ->
177177
{ok,router_pb:'Etcd.AuthUserGetResponse'()}|{error,eetcd_error()}.
178178
user_get(Context, Name) ->
179-
C1 = eetcd:new(Context),
179+
C1 = new(Context),
180180
C2 = maps:put(name, Name, C1),
181181
eetcd_auth_gen:user_get(C2).
182182

@@ -194,10 +194,10 @@ user_get(Context, Name) ->
194194
%%% </dd> </dl>
195195
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
196196
%%% @end
197-
-spec user_list(name()|context()) ->
197+
-spec user_list(new_context()) ->
198198
{ok,router_pb:'Etcd.AuthUserListResponse'()}|{error,eetcd_error()}.
199199
user_list(Context) ->
200-
eetcd_auth_gen:user_list(eetcd:new(Context)).
200+
eetcd_auth_gen:user_list(new(Context)).
201201

202202
%%% @doc UserRevokeRole revokes a role of a user.
203203
%%% <dl>
@@ -213,10 +213,10 @@ user_list(Context) ->
213213
%%% </dd> </dl>
214214
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
215215
%%% @end
216-
-spec user_revoke_role(name()|context(), iodata(), iodata()) ->
216+
-spec user_revoke_role(new_context(), iodata(), iodata()) ->
217217
{ok,router_pb:'Etcd.AuthUserRevokeRoleResponse'()}|{error,eetcd_error()}.
218218
user_revoke_role(Context, Name, Role) ->
219-
C1 = eetcd:new(Context),
219+
C1 = new(Context),
220220
C2 = maps:put(name, Name, C1),
221221
C3 = maps:put(role, Role, C2),
222222
eetcd_auth_gen:user_revoke_role(C3).
@@ -235,10 +235,10 @@ user_revoke_role(Context, Name, Role) ->
235235
%%% </dd> </dl>
236236
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
237237
%%% @end
238-
-spec role_add(name()|context(), iodata()) ->
238+
-spec role_add(new_context(), iodata()) ->
239239
{ok,router_pb:'Etcd.AuthRoleAddResponse'()}|{error,eetcd_error()}.
240240
role_add(Context, Name) ->
241-
C1 = eetcd:new(Context),
241+
C1 = new(Context),
242242
C2 = maps:put(name, Name, C1),
243243
eetcd_auth_gen:role_add(C2).
244244

@@ -257,10 +257,10 @@ role_add(Context, Name) ->
257257
%%% </dd> </dl>
258258
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
259259
%%% @end
260-
-spec role_grant_permission(name()|context(), iodata(), iodata(), iodata(), 'READ' | 'WRITE' | 'READWRITE') ->
260+
-spec role_grant_permission(new_context(), iodata(), iodata(), iodata(), 'READ' | 'WRITE' | 'READWRITE') ->
261261
{ok,router_pb:'Etcd.AuthRoleGrantPermissionResponse'()}|{error,eetcd_error()}.
262262
role_grant_permission(Context, Name, Key, RangeEnd, PermType) ->
263-
C1 = eetcd:new(Context),
263+
C1 = new(Context),
264264
C2 = maps:put(name, Name, C1),
265265
Permission = #{key => Key, range_end => RangeEnd, permType => PermType},
266266
C3 = maps:put(perm, Permission, C2),
@@ -280,10 +280,10 @@ role_grant_permission(Context, Name, Key, RangeEnd, PermType) ->
280280
%%% </dd> </dl>
281281
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
282282
%%% @end
283-
-spec role_get(name()|context(), iodata()) ->
283+
-spec role_get(new_context(), iodata()) ->
284284
{ok,router_pb:'Etcd.AuthRoleGetResponse'()}|{error,eetcd_error()}.
285285
role_get(Context, Role) ->
286-
C1 = eetcd:new(Context),
286+
C1 = new(Context),
287287
C2 = maps:put(role, Role, C1),
288288
eetcd_auth_gen:role_get(C2).
289289

@@ -301,10 +301,10 @@ role_get(Context, Role) ->
301301
%%% </dd> </dl>
302302
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
303303
%%% @end
304-
-spec role_list(name()|context()) ->
304+
-spec role_list(new_context()) ->
305305
{ok,router_pb:'Etcd.AuthRoleListResponse'()}|{error,eetcd_error()}.
306306
role_list(Context) ->
307-
eetcd_auth_gen:role_list(eetcd:new(Context)).
307+
eetcd_auth_gen:role_list(new(Context)).
308308

309309
%%% @doc RoleRevokePermission revokes a permission from a role.
310310
%%% <dl>
@@ -320,10 +320,10 @@ role_list(Context) ->
320320
%%% </dd> </dl>
321321
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
322322
%%% @end
323-
-spec role_revoke_permission(name()|context(), iodata(), iodata(), iodata()) ->
323+
-spec role_revoke_permission(new_context(), iodata(), iodata(), iodata()) ->
324324
{ok,router_pb:'Etcd.AuthRoleRevokePermissionResponse'()}|{error,eetcd_error()}.
325325
role_revoke_permission(Context, Role, Key, RangeEnd) ->
326-
C1 = eetcd:new(Context),
326+
C1 = new(Context),
327327
C2 = maps:put(role, Role, C1),
328328
C3 = maps:put(key, Key, C2),
329329
C4 = maps:put(range_end, RangeEnd, C3),
@@ -343,15 +343,15 @@ role_revoke_permission(Context, Role, Key, RangeEnd) ->
343343
%%% </dd> </dl>
344344
%%% {@link eetcd_auth:with_timeout/2} {@link eetcd_auth:new/1}
345345
%%% @end
346-
-spec role_delete(name()|context(), iodata()) ->
346+
-spec role_delete(new_context(), iodata()) ->
347347
{ok,router_pb:'Etcd.AuthRoleDeleteResponse'()}|{error,eetcd_error()}.
348348
role_delete(Context, Role) ->
349-
C1 = eetcd:new(Context),
349+
C1 = new(Context),
350350
C2 = maps:put(role, Role, C1),
351351
eetcd_auth_gen:role_delete(C2).
352352

353353
%%% @doc Create context for request.
354-
-spec new(atom()|reference()) -> context().
354+
-spec new(new_context()) -> context().
355355
new(Context) -> eetcd:new(Context).
356356

357357
%% @doc Timeout is an integer greater than zero which specifies how many milliseconds to wait for a reply,

src/eetcd_cluster.erl

+10-10
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
%%% </dd> </dl>
2424
%%% {@link eetcd_cluster:with_timeout/2} {@link eetcd_cluster:new/1}
2525
%%% @end
26-
-spec member_list(context()|name()) ->
26+
-spec member_list(new_context()) ->
2727
{ok,router_pb:'Etcd.MemberListResponse'()}|{error,eetcd_error()}.
2828
member_list(Context) -> eetcd_cluster_gen:member_list(new(Context)).
2929

@@ -41,9 +41,9 @@ member_list(Context) -> eetcd_cluster_gen:member_list(new(Context)).
4141
%%% </dd> </dl>
4242
%%% {@link eetcd_cluster:with_timeout/2} {@link eetcd_cluster:new/1}
4343
%%% @end
44-
-spec member_add(context()|name(), PeerURLs) ->
45-
{ok,router_pb:'Etcd.MemberListResponse'()}
46-
| {error, {'grpc_error', non_neg_integer(), binary()}} | {error, term()}
44+
-spec member_add(new_context(), PeerURLs) ->
45+
{ok,router_pb:'Etcd.MemberAddResponse'()}
46+
| {error, eetcd:eetcd_error()}
4747
when PeerURLs :: [iodata()].
4848
member_add(Context, PeerAddrs) when is_list(PeerAddrs) ->
4949
C1 = new(Context),
@@ -65,8 +65,8 @@ member_add(Context, PeerAddrs) when is_list(PeerAddrs) ->
6565
%%% </dd> </dl>
6666
%%% {@link eetcd_cluster:with_timeout/2} {@link eetcd_cluster:new/1}
6767
%%% @end
68-
-spec member_add_as_learner(context()|name(), PeerURLs) ->
69-
{ok,router_pb:'Etcd.MemberListResponse'()}
68+
-spec member_add_as_learner(new_context(), PeerURLs) ->
69+
{ok,router_pb:'Etcd.MemberAddResponse'()}
7070
| {error, {'grpc_error', non_neg_integer(), binary()}} | {error, term()}
7171
when PeerURLs :: [iodata()].
7272
member_add_as_learner(Context, PeerAddrs) when is_list(PeerAddrs) ->
@@ -89,7 +89,7 @@ member_add_as_learner(Context, PeerAddrs) when is_list(PeerAddrs) ->
8989
%%% </dd> </dl>
9090
%%% {@link eetcd_cluster:with_timeout/2} {@link eetcd_cluster:new/1}
9191
%%% @end
92-
-spec member_remove(context()|name(), pos_integer()) ->
92+
-spec member_remove(new_context(), pos_integer()) ->
9393
{ok,router_pb:'Etcd.MemberRemoveResponse'()}|{error,eetcd_error()}.
9494
member_remove(Context, Id) when is_integer(Id) ->
9595
C1 = new(Context),
@@ -110,7 +110,7 @@ member_remove(Context, Id) when is_integer(Id) ->
110110
%%% </dd> </dl>
111111
%%% {@link eetcd_cluster:with_timeout/2} {@link eetcd_cluster:new/1}
112112
%%% @end
113-
-spec member_update(context()|name(), pos_integer(), [list()]) ->
113+
-spec member_update(new_context(), pos_integer(), [list()]) ->
114114
{ok,router_pb:'Etcd.MemberUpdateResponse'()}|{error,eetcd_error()}.
115115
member_update(Context, Id, PeerAddrs)
116116
when is_integer(Id) andalso is_list(PeerAddrs) ->
@@ -133,15 +133,15 @@ member_update(Context, Id, PeerAddrs)
133133
%%% </dd> </dl>
134134
%%% {@link eetcd_cluster:with_timeout/2} {@link eetcd_cluster:new/1}
135135
%%% @end
136-
-spec member_promote(context()|name(), pos_integer()) ->
136+
-spec member_promote(new_context(), pos_integer()) ->
137137
{ok,router_pb:'Etcd.MemberPromoteResponse'()}|{error,eetcd_error()}.
138138
member_promote(Context, Id) when is_integer(Id) ->
139139
C1 = new(Context),
140140
C2 = maps:put('ID', Id, C1),
141141
eetcd_cluster_gen:member_promote(C2).
142142

143143
%%% @doc Create context for request.
144-
-spec new(atom()|reference()) -> context().
144+
-spec new(new_context()) -> context().
145145
new(Context) -> eetcd:new(Context).
146146

147147
%% @doc Timeout is an integer greater than zero which specifies how many milliseconds to wait for a reply,

0 commit comments

Comments
 (0)