Skip to content

Commit

Permalink
Listen to eqWAlizer
Browse files Browse the repository at this point in the history
  • Loading branch information
g-andrade committed Aug 7, 2022
1 parent e15d129 commit 33cb973
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 29 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed

- a few wrong specs
- `rebar3_lint` warnings on OTP 25
- `rebar3_hank` warnings on OTP 25
- Dialyzer warnings on OTP 25
- a few eqWAlizer warnings

## [2.3.1] - 2022-04-19

Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ elvis-linter:
dialyzer:
@rebar3 dialyzer

eqwalizer:
@rebar3 as eqwalizer,test compile
elp eqwalize-all

test: cli
@rebar3 do eunit, ct, cover
./locus check --log-level debug test/priv/GeoLite2-Country.tar.gz
Expand Down
2 changes: 2 additions & 0 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
%% == Dependencies and plugins ==

{deps, [
% {eqwalizer_support, {git_subdir, "https://github.com/whatsapp/eqwalizer.git", {branch, "main"}, "eqwalizer_support"}
{tls_certificate_check, "~> 1.9"}
]}.

{project_plugins, [
% {eqwalizer_rebar3, {git_subdir, "https://github.com/whatsapp/eqwalizer.git", {branch, "main"}, "eqwalizer_rebar3"}},
{rebar3_ex_doc, "0.2.8"},
{rebar3_hank, "1.3.0"}, % excluded on OTP 22 (see rebar.config.script)
{rebar3_hex, "7.0.1"},
Expand Down
6 changes: 3 additions & 3 deletions src/locus_filesystem_load.erl
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@
-record(state, {
owner_pid :: pid(),
source :: source(),
previously_modified_on :: calendar:datetime() | undefined
previously_modified_on :: calendar:datetime() | unknown
}).
-type state() :: #state{}.

%% ------------------------------------------------------------------
%% API Function Definitions
%% ------------------------------------------------------------------

-spec start_link(source(), calendar:datetime() | undefined) -> {ok, pid()}.
-spec start_link(source(), calendar:datetime() | unknown) -> {ok, pid()}.
%% @private
start_link(Source, PrevModificationDT) ->
gen_server:start_link(?MODULE, [self(), Source, PrevModificationDT], []).
Expand All @@ -111,7 +111,7 @@ start_link(Source, PrevModificationDT) ->
when InitArg :: OwnerPid | Source | PrevModificationDT,
OwnerPid :: pid(),
Source :: source(),
PrevModificationDT :: calendar:datetime() | undefined.
PrevModificationDT :: calendar:datetime() | unknown.
%% @private
init([OwnerPid, Source, PrevModificationDT]) ->
_ = process_flag(trap_exit, true),
Expand Down
10 changes: 5 additions & 5 deletions src/locus_loader.erl
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ finish_initialization(State)
UpdatedState = maybe_mock_fetch_metadata_for_last_successful_load(State),
CachedDatabasePath = cached_database_path(UpdatedState),
Source = {cache, CachedDatabasePath},
{ok, FetcherPid} = locus_filesystem_load:start_link(Source, undefined),
{ok, FetcherPid} = locus_filesystem_load:start_link(Source, unknown),
UpdatedState#state{ fetcher_pid = FetcherPid, fetcher_source = Source };
finish_initialization(State) ->
schedule_update(0, State).
Expand Down Expand Up @@ -496,15 +496,15 @@ cached_database_path_for_maxmind_edition_name(Edition, MaybeDate) ->
DirectoryPath = cache_directory_path(),
BinEdition = atom_to_binary(Edition, utf8),
BaseFilename = locus_util:filesystem_safe_name(BinEdition),
FilenameIoData =
FilenameChardata =
case MaybeDate of
undefined ->
io_lib:format("~ts.mmdb.gz", [BaseFilename]);
{Year, Month, Day} ->
io_lib:format("~ts.~4..0B-~2..0B-~2..0B.mmdb.gz",
[BaseFilename, Year, Month, Day])
end,
Filename = unicode:characters_to_list(FilenameIoData),
Filename = [_|_] = unicode:characters_to_list(FilenameChardata),
filename:join(DirectoryPath, Filename).

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

-spec cache_directory_path() -> nonempty_string().
Expand Down
2 changes: 1 addition & 1 deletion src/locus_logger.erl
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ maybe_truncate_url(URL) ->
URL
end.

-spec resumed_source(locus_loader:source()) -> cache | remote | filesystem.
-spec resumed_source(locus_loader:source()) -> cache | remote | filesystem | local.
resumed_source({SourceType, _SourceLocation}) ->
SourceType.

Expand Down
13 changes: 9 additions & 4 deletions src/locus_maxmind_download.erl
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,11 @@ handle_cast(_Cast, State) ->
{stop, unexpected_cast, State}.

-spec handle_info(term(), state())
-> {noreply, state()} |
{stop, normal, state()} |
{stop, unexpected_info, state()}.
-> {noreply, state()}
| {stop, normal, state()}
| {stop, {database_download_stopped, pid(), term()}, state()}
| {stop, {checksum_download_stopped, pid(), term()}, state()}
| {stop, unexpected_info, state()}.
%% @private
handle_info({DatabaseDownloadPid, Msg}, State)
when DatabaseDownloadPid =:= State#state.database_download_pid ->
Expand Down Expand Up @@ -452,7 +454,10 @@ notify_owner_process(OwnerPid, Msg) ->
_ = erlang:send(OwnerPid, {self(), Msg}, [noconnect]),
ok.

-spec handle_linked_process_death(pid(), term(), state()) -> {stop, normal, state()}.
-spec handle_linked_process_death(pid(), term(), state())
-> {stop, normal, state()}
| {stop, {database_download_stopped, pid(), term()}, state()}
| {stop, {checksum_download_stopped, pid(), term()}, state()}.
handle_linked_process_death(Pid, _, State)
when Pid =:= State#state.owner_pid ->
{stop, normal, State};
Expand Down
6 changes: 4 additions & 2 deletions src/locus_mmdb.erl
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ unpack_tree_data_and_data_section(Metadata, TreeAndDataSection) ->
<<_:TreeSize/bytes, MissingData/bits>> ->
{error, {missing_data_after_tree,
{{required, {128, bits}},
{bot_got, {bit_size(MissingData), bits}},
{but_got, {bit_size(MissingData), bits}},
{at_offset, TreeSize},
{with_metadata, Metadata}}}};
<<MissingTree/bytes>> ->
Expand All @@ -164,7 +164,9 @@ unpack_tree_data_and_data_section(Metadata, TreeAndDataSection) ->
when Address :: inet:ip_address() | string() | unicode:unicode_binary(),
Database :: database(),
Entry :: locus_mmdb_data:value(),
ErrorReason :: term().
ErrorReason :: (database_unknown | database_not_loaded |
{invalid_address, Address} |
ipv4_database).
lookup_address(Address, Database) ->
case locus_util:parse_ip_address(Address) of
{ok, ParsedAddress} ->
Expand Down
8 changes: 4 additions & 4 deletions src/locus_mmdb_check.erl
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@
:: {bad_chunk_in_data_section,
#{position := non_neg_integer(),
why := term(),
under := #{path := [non_neg_integer()]}}
under := #{path := [{non_neg_integer(), term()}]}}
}.
-export_type([bad_chunk_in_data_section/0]).

-type map_key_of_wrong_type_in_data_section()
:: {map_key_of_wrong_type_in_data_section,
#{position := non_neg_integer(),
key := term(),
under := #{path := [non_neg_integer()]}}
under := #{path := [{non_neg_integer(), term()}]}}
}.
-export_type([map_key_of_wrong_type_in_data_section/0]).

Expand All @@ -93,7 +93,7 @@
#{position := non_neg_integer(),
original_data := binary(),
error := term(),
under := #{path := [non_neg_integer()]}}
under := #{path := [{non_neg_integer(), term()}]}}
}.
-export_type([invalid_utf8_string_in_data_section/0]).

Expand All @@ -113,7 +113,7 @@
:: {unprintable_utf8_string_in_data_section,
#{position := non_neg_integer(),
value := unicode:unicode_binary(),
under := #{path := [non_neg_integer()]}}
under := #{path := [{non_neg_integer(), term()}]}}
}.
-export_type([unprintable_utf8_string_in_data_section/0]).

Expand Down
4 changes: 2 additions & 2 deletions src/locus_mmdb_check_journal.erl
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ map_key_of_wrong_type_in_data_section(Journal, Position, Key, Path) ->
register_error(Journal, Error).

-spec invalid_utf8_string_in_data_section(t(), non_neg_integer(), binary(),
term(), [non_neg_integer()])
term(), [{non_neg_integer(), term()}])
-> true.
invalid_utf8_string_in_data_section(Journal, Position, OriginalData, ValidationError, Path) ->
Error = invalid_utf8_string_in_data_section(Position, OriginalData, ValidationError, Path),
register_error(Journal, Error).

-spec unprintable_utf8_string_in_data_section(t(), non_neg_integer(), unicode:unicode_binary(),
[non_neg_integer()])
[{non_neg_integer(), term()}])
-> true.
unprintable_utf8_string_in_data_section(Journal, Position, Value, Path) ->
Warning = unprintable_utf8_string_in_data_section(Position, Value, Path),
Expand Down
6 changes: 3 additions & 3 deletions src/locus_mmdb_data_raw.erl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
-type array() :: {array, [value()]}.
-export_type([array/0]).

-type boolean_() :: {bool, locus_mmdb_data:boolean_()}.
-type boolean_() :: {boolean, locus_mmdb_data:boolean_()}.
-export_type([boolean_/0]).

-type float_() :: {float, locus_mmdb_data:float_()}.
Expand All @@ -96,8 +96,8 @@
| map
| int32
| uint64
| int128
| uint128
| array
| bool
| boolean
| float.
-export_type([value_tag/0]).
6 changes: 3 additions & 3 deletions src/locus_mmdb_tree.erl
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ extract_node_records(Offset, Data, RecordSize) ->
Left = (LeftHigh bsl LeftWholeSz) bor LeftLow,
{Left, Right}.

-spec bitstring_ip_address_prefix(<<_:32>>, 0..32) -> ip4_address_prefix();
(<<_:128>>, 0..128) -> ip6_address_prefix().
-spec bitstring_ip_address_prefix(<<_:32>> | <<_:128>>, 0..32 | 0..128)
-> ip4_address_prefix() | ip6_address_prefix().
%% @private
bitstring_ip_address_prefix(BitAddress, SuffixSize) when bit_size(BitAddress) =:= 32 ->
PrefixSize = 32 - SuffixSize,
Expand Down Expand Up @@ -440,7 +440,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 @@ -146,7 +146,8 @@ init([Counters, Concurrency]) ->

-spec handle_call(term(), {pid(), reference()}, state())
-> {noreply, state()} |
{reply, {ok, 0}, state()} |
{reply, {ok, 0, 1}, state()} |
{stop, normal, stop, state()} |
{stop, {unexpected_call, #{request := _, from := {pid(), reference()}}}, state()}.
handle_call(take_index, From, State) ->
case State#state.walk_started of
Expand Down
2 changes: 1 addition & 1 deletion src/locus_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ is_date(Date) ->
_:_ -> false
end.

-spec purge_term_of_very_large_binaries(term()) -> term().
-spec purge_term_of_very_large_binaries(T) -> 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),
Expand Down

0 comments on commit 33cb973

Please sign in to comment.