Skip to content

Commit

Permalink
Merge pull request #259 from inaka/feature/improve-static-code-analysis
Browse files Browse the repository at this point in the history
Feature/improve static code analysis
  • Loading branch information
dsrosario authored Jul 31, 2024
2 parents 28f5bea + f10c131 commit 503a51f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 13 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ${{matrix.os}}
strategy:
matrix:
otp_vsn: [24, 25, 26]
otp_vsn: [24, 25, 26, 27]
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v2
Expand All @@ -23,4 +23,6 @@ jobs:
rebar3-version: '3.22.1'
- run: rebar3 as test xref
- run: rebar3 as test dialyzer
- run: rebar3 hank
- run: rebar3 lint
# - run: rebar3 as test ct
14 changes: 9 additions & 5 deletions elvis.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
filter => "*.erl",
ruleset => erl_files,
rules => [
{elvis_style, line_length, #{limit => 100}}
{elvis_text_style, line_length, #{limit => 100}}
, {elvis_style, god_modules, #{limit => 25, ignore => [apns_connection]}}
, {elvis_style, no_author, disable}
, {elvis_style, no_space, disable}
, {elvis_style, no_if_expression, #{ignore => [apns_connection]}}
, {elvis_style, dont_repeat_yourself, #{min_complexity => 20}}
, {elvis_style, export_used_types, #{ignore => [apns_meta_SUITE,
apns_os_SUITE,
connection_SUITE,
feedback_SUITE]}}
]
},
#{dirs => ["."],
filter => "Makefile",
ruleset => makefiles
},
#{dirs => ["."],
filter => "rebar.config",
ruleset => rebar_config
Expand Down
14 changes: 14 additions & 0 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
{base64url, "1.0.1"}
]}.

%% == Plugins ==
{project_plugins, [
{rebar3_hank, "1.4.1"},
{rebar3_lint, "3.2.6"},
{rebar3_depup, "0.4.0"}
]}.

%% == Profiles ==

{profiles, [
Expand Down Expand Up @@ -114,3 +121,10 @@
locals_not_used,
deprecated_function_calls
]}.

%% == Hank ==
{hank, [
{ignore, [
"test/*_SUITE.erl"
]}
]}.
8 changes: 5 additions & 3 deletions src/apns.erl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
, apns_push_type => binary()
, apns_auth_token => binary()
}.
-type feedback() :: apns_feedback:feedback().

%%%===================================================================
%%% API
Expand Down Expand Up @@ -185,7 +184,7 @@ default_headers() ->
default_headers(Headers, #{apns_push_type => <<"alert">>}).

%% Requests for feedback to APNs. This requires Provider Certificate.
-spec get_feedback() -> [feedback()] | {error, term()} | timeout.
-spec get_feedback() -> [apns_feedback:feedback()] | {error, term()} | timeout.
get_feedback() ->
{ok, Host} = application:get_env(apns, feedback_host),
{ok, Port} = application:get_env(apns, feedback_port),
Expand All @@ -201,7 +200,10 @@ get_feedback() ->
get_feedback(Config).

%% Requests for feedback to APNs. This requires Provider Certificate.
-spec get_feedback(apns_feedback:feedback_config()) -> [feedback()] | {error, term()} | timeout.
-spec get_feedback(apns_feedback:feedback_config())
-> [apns_feedback:feedback()]
| {error, term()}
| timeout.
get_feedback(Config) ->
apns_feedback:get_feedback(Config).

Expand Down
11 changes: 7 additions & 4 deletions src/apns_connection.erl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
, body := binary()
}.

-type state() :: #{ connection := connection()
-opaque state() :: #{ connection := connection()
, gun_pid => pid()
, gun_streams => #{gun:stream_ref() => stream_data()}
, max_gun_streams := non_neg_integer()
Expand All @@ -111,6 +111,9 @@
, backoff_ceiling := non_neg_integer()
}.

-export_type([keydata/0,
state/0]).

%%%===================================================================
%%% API
%%%===================================================================
Expand Down Expand Up @@ -622,9 +625,9 @@ get_headers(Headers) ->
, {<<"authorization">>, apns_auth_token}
],
F = fun({ActualHeader, Key}) ->
case (catch maps:get(Key, Headers)) of
{'EXIT', {{badkey, Key}, _}} -> [];
Value -> [{ActualHeader, Value}]
case maps:find(Key, Headers) of
error -> [];
{ok, Value} -> [{ActualHeader, Value}]
end
end,
lists:flatmap(F, List).
Expand Down

0 comments on commit 503a51f

Please sign in to comment.