Skip to content

Commit

Permalink
Merge pull request #22 from SemanticSugar/RTI-4670-dialyzer-xref-lint
Browse files Browse the repository at this point in the history
[RTI-4670] Move to rebar3, add xref, dialyzer and linting
  • Loading branch information
elbrujohalcon authored Jan 22, 2019
2 parents f1f99e5 + 1b15076 commit b2fb96b
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 50 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/_build
/ebin
/doc
/_test
Expand All @@ -9,4 +10,4 @@
*.swp
*.pyc
.idea
*.iml
*.iml
29 changes: 13 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
PREFIX:=../
DEST:=$(PREFIX)$(PROJECT)
REBAR=rebar3

REBAR=./rebar
all: compile test edoc

all:
@$(REBAR) get-deps compile
compile:
@$(REBAR) compile

edoc:
@$(REBAR) doc
@$(REBAR) edoc

test:
@rm -rf .eunit
@mkdir -p .eunit
@$(REBAR) skip_deps=true eunit
test: lint xref dialyzer
@$(REBAR) eunit

clean:
@$(REBAR) clean

build_plt:
@$(REBAR) build-plt

dialyzer:
@$(REBAR) dialyze
@$(REBAR) dialyzer || $(REBAR) dialyzer

xref:
@$(REBAR) xref

app:
@$(REBAR) create template=mochiwebapp dest=$(DEST) appid=$(PROJECT)
lint:
@$(REBAR) lint
26 changes: 26 additions & 0 deletions elvis.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
{
elvis,
[
{config,
[#{dirs => ["src"],
filter => "*.erl",
ruleset => erl_files,
rules => [
{elvis_style, line_length, #{limit => 150}},
{elvis_style, god_modules, #{limit => 50}},
{elvis_style, dont_repeat_yourself, #{min_complexity => 20}},
{elvis_style, nesting_level, #{level => 4}},
%% the default rule included {right, ","} and not {right, "=>"} or {left, "=>"}
{
elvis_style,
operator_spaces,
#{rules => [{right, "++"}, {left, "++"}, {right, "=>"}, {left, "=>"}]}
}
]
}
]
}
]
}
].
4 changes: 2 additions & 2 deletions include/dinerl_types.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

-type jsonf() :: any().

-type clientarguments() :: {access_key_id(), secret_access_key(), zone(), token(), rfcdate(), integer()}.
-type clientarguments() :: {{access_key_id(), secret_access_key()}, zone(), rfcdate()}.

-type method() :: batch_get_item | get_item | put_item | delete_item |
update_item | create_table | list_tables | describe_table |
update_table | delete_table | q | scan.
update_table | delete_table | q | scan | query_item_20111205 | query_item_20120810.

-type result() :: {ok, any()} | {error, string(), string()} | {error, term(), timeout | string()}.

Expand Down
13 changes: 13 additions & 0 deletions old.rebar.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
%% -*- erlang -*-
{erl_opts, [debug_info]}.

{deps, [
{lhttpc, ".*",
{git, "https://github.com/ferd/lhttpc.git", {branch, "master"}}},

{erliam, ".*",
{git, "https://github.com/AdRoll/erliam.git", {tag, "v0.1.1"}}}
]}.

{cover_enabled, true}.
{eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]}.
28 changes: 22 additions & 6 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,28 @@
{erl_opts, [debug_info]}.

{deps, [
{lhttpc, ".*",
{git, "https://github.com/ferd/lhttpc.git", {branch, "master"}}},

{erliam, ".*",
{git, "https://github.com/AdRoll/erliam.git", {tag, "v0.1.1"}}}
]}.
{lhttpc, {git,"git://github.com/ferd/lhttpc.git", {tag, "1.2.9"}}},
{erliam, {git, "https://github.com/AdRoll/erliam.git", {tag, "v0.1.2"}}}
]}.

{cover_enabled, true}.

{plugins, [{rebar3_lint, "0.1.10"}]}.

{dialyzer, [
{warnings, [unknown, no_return, error_handling]},
{get_warnings, true},
{plt_apps, top_level_deps},
{plt_extra_apps, []},
{plt_location, local},
{base_plt_apps, [erts, stdlib, kernel, sasl]},
{base_plt_location, global}
]}.

{xref_checks, [
undefined_function_calls,
locals_not_used,
deprecated_function_calls
]}.

{eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]}.
8 changes: 8 additions & 0 deletions rebar.config.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
IsRebar3 = erlang:function_exported(rebar3, main, 1),
case IsRebar3 of
false ->
{ok, OldConfig} = file:consult("old.rebar.config"),
OldConfig;
true ->
CONFIG
end.
12 changes: 12 additions & 0 deletions rebar.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[{<<"erliam">>,
{git,"https://github.com/AdRoll/erliam.git",
{ref,"a5b362f72cf95a085b0789e9a9af14d71adebbed"}},
0},
{<<"jiffy">>,
{git,"https://github.com/davisp/jiffy.git",
{ref,"06aaf440e091c9fd5f8aea557ac760a33bd37130"}},
1},
{<<"lhttpc">>,
{git,"git://github.com/ferd/lhttpc.git",
{ref,"28d5562be7e53576b624a6f82deac7303ce8f2dd"}},
0}].
3 changes: 2 additions & 1 deletion src/dinerl.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
public_key,
ssl,
xmerl,
erliam
erliam,
lhttpc
]
}]}.
2 changes: 1 addition & 1 deletion src/dinerl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ api(Name, Body, Timeout, Region) ->
create_table(Name, Key, ReadsPerSecond, WritesPerSecond) ->
create_table(Name, Key, ReadsPerSecond, WritesPerSecond, undefined).

-spec create_table(string()|binary(), keyschema(), integer(), integer(), integer()) -> jsonf().
-spec create_table(string()|binary(), keyschema(), integer(), integer(), undefined | integer()) -> jsonf().
create_table(Name, Key, ReadsPerSecond, WritesPerSecond, Timeout) ->
api(create_table,
[{<<"TableName">>, Name},
Expand Down
43 changes: 22 additions & 21 deletions src/dmochijson2.erl
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@
-define(IS_WHITESPACE(C),
(C =:= $\s orelse C =:= $\t orelse C =:= $\r orelse C =:= $\n)).

%% @type json_string() = atom | binary()
%% @type json_number() = integer() | float()
%% @type json_array() = [json_term()]
%% @type json_object() = {struct, [{json_string(), json_term()}]}
%% @type json_eep18_object() = {[{json_string(), json_term()}]}
%% @type json_iolist() = {json, iolist()}
%% @type json_term() = json_string() | json_number() | json_array() |
%% json_object() | json_eep18_object() | json_iolist()
-type json_string() :: atom | binary().
-type json_number() :: integer() | float().
-type json_array() :: [json_term()].
-type json_object() :: {struct, [{json_string(), json_term()}]}.
-type json_eep18_object() :: {[{json_string(), json_term()}]}.
-type json_iolist() :: {json, iolist()}.
-type json_term() :: json_string() | json_number() | json_array() |
json_object() | json_eep18_object() | json_iolist().

-record(encoder, {handler=null,
utf8=false}).
Expand All @@ -92,6 +92,7 @@ encoder(Options) ->

%% @spec encode(json_term()) -> iolist()
%% @doc Encode the given as JSON to an iolist.
-spec encode(json_term()) -> iolist().
encode(Any) ->
json_encode(Any, #encoder{}).

Expand Down Expand Up @@ -445,18 +446,18 @@ tokenize_string(B, S=#decoder{offset=O}, Acc) ->
<<_:O/binary, "\\t", _/binary>> ->
tokenize_string(B, ?ADV_COL(S, 2), [$\t | Acc]);
<<_:O/binary, "\\u", C3, C2, C1, C0, Rest/binary>> ->
C = erlang:list_to_integer([C3, C2, C1, C0], 16),
if C > 16#D7FF, C < 16#DC00 ->
%% coalesce UTF-16 surrogate pair
<<"\\u", D3, D2, D1, D0, _/binary>> = Rest,
D = erlang:list_to_integer([D3,D2,D1,D0], 16),
[CodePoint] = xmerl_ucs:from_utf16be(<<C:16/big-unsigned-integer,
D:16/big-unsigned-integer>>),
Acc1 = lists:reverse(xmerl_ucs:to_utf8(CodePoint), Acc),
tokenize_string(B, ?ADV_COL(S, 12), Acc1);
true ->
Acc1 = lists:reverse(xmerl_ucs:to_utf8(C), Acc),
tokenize_string(B, ?ADV_COL(S, 6), Acc1)
case erlang:list_to_integer([C3, C2, C1, C0], 16) of
C when C > 16#D7FF, C < 16#DC00 ->
%% coalesce UTF-16 surrogate pair
<<"\\u", D3, D2, D1, D0, _/binary>> = Rest,
D = erlang:list_to_integer([D3,D2,D1,D0], 16),
[CodePoint] = xmerl_ucs:from_utf16be(<<C:16/big-unsigned-integer,
D:16/big-unsigned-integer>>),
Acc1 = lists:reverse(xmerl_ucs:to_utf8(CodePoint), Acc),
tokenize_string(B, ?ADV_COL(S, 12), Acc1);
C ->
Acc1 = lists:reverse(xmerl_ucs:to_utf8(C), Acc),
tokenize_string(B, ?ADV_COL(S, 6), Acc1)
end;
<<_:O/binary, C1, _/binary>> when C1 < 128 ->
tokenize_string(B, ?INC_CHAR(S, C1), [C1 | Acc]);
Expand Down Expand Up @@ -788,7 +789,7 @@ key_encode_test() ->
?assertEqual(
<<"{\"foo\":1}">>,
iolist_to_binary(encode({struct, [{"foo", 1}]}))),
?assertEqual(
?assertEqual(
<<"{\"foo\":1}">>,
iolist_to_binary(encode([{foo, 1}]))),
?assertEqual(
Expand Down
6 changes: 4 additions & 2 deletions src/dynamodb.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

-export([call/5, call/6]).

%% @todo Remove when lhttpc's specs are fixed
-dialyzer({nowarn_function, [call/6, submit/4]}).

-spec endpoint(zone()) -> endpoint().
endpoint("us-east-1" ++ _R) -> "dynamodb.us-east-1.amazonaws.com";
Expand All @@ -25,7 +27,7 @@ region("eu-west-1" ++ _R) -> "eu-west-1".


-spec call(awsv4:credentials(), zone(), string(),
aws_datetime(), any(), undefined | pos_integer()) -> result().
aws_datetime(), iolist(), undefined | pos_integer()) -> result().
call(Credentials, Zone, Target, ISODate, Body, undefined) ->
call(Credentials, Zone, Target, ISODate, Body, 1000);

Expand All @@ -47,7 +49,7 @@ call(Credentials, Zone, Target, RFCDate, Body) ->
call(Credentials, Zone, Target, RFCDate, Body, 1000).


-spec submit(endpoint(), headers(), any(), integer()) -> result().
-spec submit(endpoint(), headers(), iolist(), integer()) -> result().
submit(Endpoint, Headers, Body, Timeout) ->
%io:format("Request:~nHeaders:~p~nBody:~n~p~n~n", [Headers, iolist_to_binary(Body)]),
case lhttpc:request(Endpoint, "POST", Headers, Body, Timeout, [{max_connections, 10000}]) of
Expand Down

0 comments on commit b2fb96b

Please sign in to comment.