Deal with dialyzer issues

We end up:
1. making the main interface (`jsx:`) more readable and easier to maintain
(this allows for easier future dropping of the use of `#config{}` for options),
2. fixing some config.-related `-spec(_).`s that weren't using proper elements,
3. having `any()` become a "specific type" - which seems like an improvement,
4. moving stuff like `list()` or `proplists:proplist()` into more appropriate types,
5. making the main config. element (`jsx_config`) "pretty" visible,
6. creating a visible distinction between a module's config. and the generic `jsx_config` elements
This commit is contained in:
Paulo F. Oliveira 2020-09-11 23:09:16 +01:00
parent 1e88fc5455
commit 3a8f364153
10 changed files with 106 additions and 52 deletions

View file

@ -49,8 +49,55 @@
-type config() :: #config{}.
-export_type([config/0]).
-type option() :: valid_flag()
| {valid_flag(), boolean()}
| {strict, [strict_option()]}
| {error_handler, fun((any(), any(), any()) -> ok)}
| {incomplete_handler, fun((any(), any(), any()) -> ok)}
| {return_maps, boolean()}
| {labels, label_option()}
| {space, non_neg_integer()}
| {indent, non_neg_integer()}
| {depth, non_neg_integer()}
| {newline, binary()}
| legacy_option()
| {legacy_option(), boolean()}.
-type legacy_option() :: strict_comments
| strict_commas
| strict_utf8
| strict_single_quotes
| strict_escapes
| strict_control_codes.
-type options() :: [option()].
-export_type([options/0]).
-type strict_option() :: comments
| trailing_commas
| utf8
| single_quotes
| escapes
| control_codes.
-type label_option() :: binary
| atom
| existing_atom
| attempt_atom.
-type valid_flag() :: escaped_forward_slashes
| escaped_strings
| unescaped_jsonp
| dirty_strings
| multi_term
| return_tail
| repeat_keys
| strict
| stream
| uescape
| error_handler
| incomplete_handler.
%% parsing of jsx config
-spec parse_config(Config::proplists:proplist()) -> config().
-spec parse_config(Config::options()) -> config().
parse_config(Config) -> parse_config(Config, #config{}).
@ -116,7 +163,7 @@ parse_strict(_Strict, _Rest, _Config) ->
-spec config_to_list(Config::config()) -> proplists:proplist().
-spec config_to_list(Config::config()) -> options().
config_to_list(Config) ->
reduce_config(lists:map(
@ -153,7 +200,7 @@ reduce_config([Else|Input], Output, Strict) ->
reduce_config(Input, [Else] ++ Output, Strict).
-spec valid_flags() -> [atom()].
-spec valid_flags() -> [valid_flag(), ...].
valid_flags() ->
[
@ -172,7 +219,7 @@ valid_flags() ->
].
-spec extract_config(Config::proplists:proplist()) -> proplists:proplist().
-spec extract_config(Config::options()) -> options().
extract_config(Config) ->
extract_parser_config(Config, []).