Skip to content

Commit

Permalink
Bump rebar3_lint to 3.2.3 and either heed or skip its warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
g-andrade committed May 4, 2024
1 parent f4d4685 commit d4e4dec
Show file tree
Hide file tree
Showing 20 changed files with 77 additions and 68 deletions.
7 changes: 6 additions & 1 deletion elvis.config
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
locus_util]
}},
{elvis_style, macro_names, disable},
{elvis_style, no_if_expression, disable}] },
{elvis_style, no_if_expression, disable},
{elvis_style, no_throw, #{
ignore => [locus_custom_fetcher,
locus_mmdb_data_codec,
locus_shared_bitarray]
}} ]},
#{ dirs => ["test/**"],
filter => "*.erl",
ruleset => erl_files,
Expand Down
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
{rebar3_ex_doc, "0.2.22"},
{rebar3_hank, "1.4.0"}, % excluded on OTP 22 (see rebar.config.script)
{rebar3_hex, "7.0.7"},
{rebar3_lint, "1.0.2"}
{rebar3_lint, "3.2.3"}
]}.

%% == Dialyzer ==
Expand Down
6 changes: 2 additions & 4 deletions src/locus_cli.erl
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,8 @@ prepare_database(DatabaseURL, LoadTimeout, SuccessHandler) ->
end,

stderr_println("Loading database from \"~ts\"...", [DatabaseURL]),
case locus:start_loader(DatabaseId, DatabaseURL, BaseOpts ++ ExtraOpts) of
ok ->
wait_for_database_load(DatabaseId, LoadTimeout, SuccessHandler)
end.
ok = locus:start_loader(DatabaseId, DatabaseURL, BaseOpts ++ ExtraOpts),
wait_for_database_load(DatabaseId, LoadTimeout, SuccessHandler).

wait_for_database_load(DatabaseId, LoadTimeout, SuccessHandler) ->
receive
Expand Down
21 changes: 12 additions & 9 deletions src/locus_custom_fetcher.erl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
-module(locus_custom_fetcher).
-behaviour(gen_server).

-include_lib("stdlib/include/assert.hrl").

%% ------------------------------------------------------------------
%% Callback Declarations
%% ------------------------------------------------------------------
Expand Down Expand Up @@ -112,7 +114,7 @@
-type event_load_attempt_dismissed() :: {load_attempt_dismissed, source()}.
-export_type([event_load_attempt_dismissed/0]).

-type source() :: {local|remote, {custom, term()}}.
-type source() :: {local | remote, {custom, term()}}.
-export_type([source/0]).

%% ------------------------------------------------------------------
Expand All @@ -133,7 +135,8 @@
args :: term(),
previous_fetch_metadata :: successful_fetch_metadata() | undefined
}).
-type state() :: #state{}.
-opaque state() :: #state{}.
-export_type([state/0]).

%% ------------------------------------------------------------------
%% "Private" API Function Definitions
Expand All @@ -153,13 +156,13 @@ source(Module, Args) ->
-spec description(module(), term()) -> description().
%% @private
description(Module, Args) ->
case Module:description(Args) of
#{database_is_stored_remotely := IsRemote,
database_is_fetched_from := _
} = Description
when is_boolean(IsRemote) ->
Description
end.
#{
database_is_stored_remotely := IsRemote,
database_is_fetched_from := _
} = Description = Module:description(Args),

?assertMatch(_ when is_boolean(IsRemote), IsRemote),
Description.

-spec start_link(source(), module(), term(), successful_fetch_metadata() | undefined)
-> {ok, pid()}.
Expand Down
4 changes: 3 additions & 1 deletion src/locus_database.erl
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@
subscribers :: [atom() | pid()],
subscriber_mons :: #{monitor() => pid()}
}).
-type state() :: #state{}.
-opaque state() :: #state{}.
-export_type([state/0]).

-type monitor() :: reference().

-record(shared_state, {
Expand Down
2 changes: 1 addition & 1 deletion src/locus_database_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ start_child(Args) ->
try supervisor:start_child(?SERVER, Args) of
Result -> Result
catch
exit:{Reason, {gen_server, call, [?SERVER|_]}}
exit:{Reason, {gen_server, call, [?SERVER | _]}}
when Reason =:= noproc;
Reason =:= normal;
Reason =:= shutdown;
Expand Down
5 changes: 3 additions & 2 deletions src/locus_filesystem_load.erl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
-type event_load_attempt_dismissed() :: {load_attempt_dismissed, source()}.
-export_type([event_load_attempt_dismissed/0]).

-type source() :: {cache|filesystem, path()}.
-type source() :: {cache | filesystem, path()}.
-export_type([source/0]).

-type success() ::
Expand All @@ -92,7 +92,8 @@
source :: source(),
previously_modified_on :: calendar:datetime() | unknown
}).
-type state() :: #state{}.
-opaque state() :: #state{}.
-export_type([state/0]).

%% ------------------------------------------------------------------
%% API Function Definitions
Expand Down
3 changes: 2 additions & 1 deletion src/locus_filesystem_store.erl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
content :: iodata(),
modified_on :: calendar:datetime()
}).
-type state() :: #state{}.
-opaque state() :: #state{}.
-export_type([state/0]).

%% ------------------------------------------------------------------
%% API Function Definitions
Expand Down
9 changes: 5 additions & 4 deletions src/locus_http_download.erl
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@
response_headers :: headers() | undefined,
response_body :: iodata() | undefined
}).
-type state() :: #state{}.
-opaque state() :: #state{}.
-export_type([state/0]).

%% ------------------------------------------------------------------
%% API Function Definitions
Expand Down Expand Up @@ -291,7 +292,7 @@ code_change(_OldVsn, #state{} = State, _Extra) ->
-spec maybe_censor_url(url(), [opt()]) -> url().
maybe_censor_url(URL, Opts) ->
case proplists:get_value(censor_query, Opts, []) of
[_|_] = CensoredKeys ->
[_ | _] = CensoredKeys ->
CensoredStringKeys = [atom_to_list(Key) || Key <- CensoredKeys],
locus_util:censor_url_query(URL, CensoredStringKeys);
[] ->
Expand Down Expand Up @@ -443,7 +444,7 @@ stream_start_redirect_for_location(Permanence, NewLocation, State) ->
end.

handle_successful_download_conclusion(Headers, Body, State) ->
ActualContentLength = integer_to_list( byte_size(Body) ),
ActualContentLength = integer_to_list(byte_size(Body)),

case lists:keyfind("content-length", 1, Headers) of
{_, DeclaredContentLength} when DeclaredContentLength =/= ActualContentLength ->
Expand Down Expand Up @@ -505,7 +506,7 @@ cancel_timeout(OptName, State) ->
end.

cancel_or_flush_timer(Timer, TimeoutMsg) ->
is_integer( erlang:cancel_timer(Timer) )
is_integer(erlang:cancel_timer(Timer))
orelse receive
TimeoutMsg -> true
after
Expand Down
12 changes: 6 additions & 6 deletions src/locus_loader.erl
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@
cacher_path :: locus_filesystem_store:path() | undefined,
cacher_source :: source() | undefined
}).
-type state() :: #state{}.
-opaque state() :: #state{}.
-export_type([state/0]).

-record(settings, {
update_period :: pos_integer(),
Expand Down Expand Up @@ -504,7 +505,7 @@ cached_database_path_for_maxmind_edition_name(Edition, MaybeDate) ->
io_lib:format("~ts.~4..0B-~2..0B-~2..0B.mmdb.gz",
[BaseFilename, Year, Month, Day])
end,
Filename = [_|_] = unicode:characters_to_list(FilenameChardata),
Filename = [_ | _] = unicode:characters_to_list(FilenameChardata),
filename:join(DirectoryPath, Filename).

-spec cached_database_path_for_url(string()) -> nonempty_string().
Expand All @@ -524,7 +525,7 @@ cached_database_path_for_custom_fetcher(Module, FetchedFrom) ->
SafeModuleName = locus_util:filesystem_safe_name(ModuleName),
Hash = erlang:phash2(FetchedFrom, 1 bsl 32),
FilenameChardata = io_lib:format("custom.~ts.~.36..b.mmdb.gz", [SafeModuleName, Hash]),
Filename = [_|_] = unicode:characters_to_list(FilenameChardata),
Filename = [_ | _] = unicode:characters_to_list(FilenameChardata),
filename:join(DirectoryPath, Filename).

-spec cache_directory_path() -> nonempty_string().
Expand Down Expand Up @@ -967,9 +968,8 @@ fetched_database_modification_datetime({filesystem, _}, #{modified_on := Modific

%-spec make_cached_database_blob(nonempty_string(), binary()) -> binary().
make_cached_database_blob(CachedTarballPath, EncodedDatabase) ->
case filename_extension_parts(CachedTarballPath) of
["gz", "mmdb" | _] -> zlib:gzip(EncodedDatabase)
end.
?assertMatch(["gz", "mmdb" | _], filename_extension_parts(CachedTarballPath)),
zlib:gzip(EncodedDatabase).

%% ------------------------------------------------------------------
%% Internal Function Definitions - Monitoring and Events
Expand Down
3 changes: 2 additions & 1 deletion src/locus_maxmind_download.erl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@
database_download_success :: undefined | locus_http_download:success(),
checksum_download_pid :: undefined | pid()
}).
-type state() :: #state{}.
-opaque state() :: #state{}.
-export_type([state/0]).

%% ------------------------------------------------------------------
%% API Function Definitions
Expand Down
23 changes: 11 additions & 12 deletions src/locus_mmdb_check.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
%% @doc API for working with MMDB - wholesomeness check
-module(locus_mmdb_check).

-include_lib("stdlib/include/assert.hrl").

%% ------------------------------------------------------------------
%% API Function Exports
%% ------------------------------------------------------------------
Expand Down Expand Up @@ -187,15 +185,16 @@ validate_data_indices(BitArray, DataSection, Journal) ->
VisitedBitArray = locus_shared_bitarray:new(byte_size(DataSection)),
MapKeysBitArray = locus_shared_bitarray:new(byte_size(DataSection)),

case run_concurrent_tasks(
fun (TaskIndex, Concurrency) ->
BatchSize = Concurrency,
BatchOffset = TaskIndex,
validate_data_indices_batch(BitArray, VisitedBitArray, MapKeysBitArray,
BatchSize, BatchOffset, DataSection,
Journal)
end)
of
Result = run_concurrent_tasks(
fun (TaskIndex, Concurrency) ->
BatchSize = Concurrency,
BatchOffset = TaskIndex,
validate_data_indices_batch(BitArray, VisitedBitArray, MapKeysBitArray,
BatchSize, BatchOffset, DataSection,
Journal)
end),

case Result of
{ok, _} ->
ok;
{error, _} = Error ->
Expand Down Expand Up @@ -223,7 +222,7 @@ spawn_concurrent_tasks(Concurrency, TaskFun) ->
|| TaskIndex <- lists:seq(0, Concurrency - 1)],

{PidsList, MonitorsList} = lists:unzip(PidMonitors),
maps:from_list( lists:zip(MonitorsList, PidsList) ).
maps:from_list(lists:zip(MonitorsList, PidsList)).

spawn_task(Fun, TaskIndex, Concurrency) ->
spawn_monitor(
Expand Down
6 changes: 2 additions & 4 deletions src/locus_mmdb_data_codec.erl
Original file line number Diff line number Diff line change
Expand Up @@ -794,10 +794,8 @@ validate_array(Aux, Count, RemainingData, Path) ->

validate_array_recur(Aux, Count, RemainingData, Path)
when Count > 0 ->
case validate_array_value(Aux, RemainingData, Path) of
{ok, DataAfterValue} ->
validate_array_recur(Aux, Count - 1, DataAfterValue, Path)
end;
{ok, DataAfterValue} = validate_array_value(Aux, RemainingData, Path),
validate_array_recur(Aux, Count - 1, DataAfterValue, Path);
validate_array_recur(_Aux, Count, RemainingData, _Path)
when Count =:= 0 ->
{ok, RemainingData}.
Expand Down
2 changes: 1 addition & 1 deletion src/locus_mmdb_metadata.erl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
Reason :: parse_or_validation_error().
parse_and_validate(EncodedDatabase) ->
case binary:matches(EncodedDatabase, <<?METADATA_MARKER>>) of
[_|_] = PossibleMetadataMarkers ->
[_ | _] = PossibleMetadataMarkers ->
{MetadataStart, _} = lists:last(PossibleMetadataMarkers),
<<TreeAndDataSection:MetadataStart/bytes,
?METADATA_MARKER,
Expand Down
10 changes: 5 additions & 5 deletions src/locus_mmdb_tree.erl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
walk_manager :: locus_mmdb_tree_walk_manager:handle(),
journal :: locus_mmdb_check_journal:t(),
data :: binary(),
max_depth :: 128|32
max_depth :: 128 | 32
}).

%% ------------------------------------------------------------------
Expand All @@ -111,7 +111,7 @@
when TreeData :: binary(),
NodeCount :: non_neg_integer(),
RecordSize :: non_neg_integer(),
IpVersion :: 4|6,
IpVersion :: 4 | 6,
DataSectionSize :: non_neg_integer(),
Tree :: t(),
Reason :: term().
Expand Down Expand Up @@ -248,7 +248,7 @@ ip_address_to_bitstring({A, B, C, D, E, F, G, H}, Tree) ->
end.

lookup_bit_address(BitAddress, RootIndex, Tree) ->
case lookup_bit_address_recur(BitAddress, _NodeIndex = RootIndex, Tree) of
case lookup_bit_address_recur(BitAddress, RootIndex, Tree) of
{ok, DataIndex} ->
{ok, DataIndex};
not_found ->
Expand Down Expand Up @@ -334,7 +334,7 @@ bitstring_ip_address_prefix(BitAddress, SuffixSize) when bit_size(BitAddress) =:
%% ------------------------------------------------------------------

tree_depth_from_path(Path) ->
floor( math:log2(Path) ) + 1.
floor(math:log2(Path)) + 1.

validate_(NodeIndex, Fun, WalkManager, Journal, Tree, Path, Depth) ->
Aux = #validation_aux{node_count = Tree#tree.node_count,
Expand Down Expand Up @@ -444,7 +444,7 @@ journal_prefix_recur(Path, Aux, Prefix)
{A, B, C, D}
end,

StringAddress = [_|_] = inet:ntoa(Address),
StringAddress = [_ | _] = inet:ntoa(Address),
StringAddress ++ "/" ++ integer_to_list(PrefixSize).

journal_path(Path, Aux) ->
Expand Down
3 changes: 2 additions & 1 deletion src/locus_mmdb_tree_walk_manager.erl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
concurrency :: pos_integer(),
free_workers :: [{pid(), reply_tag()}]
}).
-type state() :: #state{}.
-opaque state() :: #state{}.
-export_type([state/0]).

-if(?OTP_RELEASE < 25).
-type reply_tag() :: reference().
Expand Down
16 changes: 7 additions & 9 deletions src/locus_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
%% @private
-module(locus_util).

-include_lib("kernel/include/file.hrl").

-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
-endif.
Expand Down Expand Up @@ -95,7 +93,7 @@ parse_ip_address(_Invalid) ->

-spec lists_anymap(fun ((term()) -> boolean() | {true, term()}), list())
-> {true, term()} | false.
lists_anymap(Fun, [H|T]) ->
lists_anymap(Fun, [H | T]) ->
case Fun(H) of
{true, Mapped} -> {true, Mapped};
true -> {true, H};
Expand Down Expand Up @@ -171,7 +169,7 @@ is_date(Date) ->
end.

-spec purge_term_of_very_large_binaries(T) -> T.
purge_term_of_very_large_binaries([H|T]) ->
purge_term_of_very_large_binaries([H | T]) ->
MappedH = purge_term_of_very_large_binaries(H),
MappedT = purge_term_of_very_large_binaries(T),
[MappedH | MappedT];
Expand Down Expand Up @@ -310,17 +308,17 @@ is_termination_reason_harmless(Reason) ->
%% ------------------------------------------------------------------

-spec lists_take_recur(term(), list(), list()) -> {ok, list()} | error.
lists_take_recur(Elem, [H|T], Acc) when Elem =:= H ->
lists_take_recur(Elem, [H | T], Acc) when Elem =:= H ->
{ok, lists:reverse(Acc, T)};
lists_take_recur(Elem, [H|T], Acc) ->
lists_take_recur(Elem, T, [H|Acc]);
lists_take_recur(Elem, [H | T], Acc) ->
lists_take_recur(Elem, T, [H | Acc]);
lists_take_recur(_, [], _) ->
error.

-spec flush_link_exit(pid(), timeout()) -> boolean().
flush_link_exit(Pid, Timeout) ->
receive
{'EXIT', Pid, _} -> true
{'EXIT', P, _} when P =:= Pid -> true
after
Timeout -> false
end.
Expand All @@ -334,7 +332,7 @@ url_query_encode_codepoint(Codepoint)
Codepoint =:= $.;
Codepoint =:= $_ ->
<<Codepoint>>;
url_query_encode_codepoint($\ ) ->
url_query_encode_codepoint(32) -> % codepoint for `$\ ` which Elvis doesnt like
<<$+>>;
url_query_encode_codepoint(Codepoint) ->
UTF8Bytes = <<Codepoint/utf8>>,
Expand Down
Loading

0 comments on commit d4e4dec

Please sign in to comment.