Browse Source

Apply efmt v0.12.0

Takeru Ohta 2 years ago
parent
commit
af04fd469a
7 changed files with 41 additions and 43 deletions
  1. 7 7
      src/jsone.app.src
  2. 2 2
      src/jsone.erl
  3. 5 10
      src/jsone_decode.erl
  4. 7 4
      src/jsone_encode.erl
  5. 4 4
      src/jsone_inet.erl
  6. 10 10
      test/jsone_decode_tests.erl
  7. 6 6
      test/jsone_encode_tests.erl

+ 7 - 7
src/jsone.app.src

@@ -1,8 +1,8 @@
 {application, jsone,
-              [{description, "Erlang JSON Library"},
-               {vsn, "1.7.0"},
-               {registered, []},
-               {applications, [kernel, stdlib]},
-               {licenses, ["MIT"]},
-               {links, [{"GitHub", "https://github.com/sile/jsone"}]},
-               {env, []}]}.
+ [{description, "Erlang JSON Library"},
+  {vsn, "1.7.0"},
+  {registered, []},
+  {applications, [kernel, stdlib]},
+  {licenses, ["MIT"]},
+  {links, [{"GitHub", "https://github.com/sile/jsone"}]},
+  {env, []}]}.

+ 2 - 2
src/jsone.erl

@@ -130,7 +130,7 @@
 
 -type json_scalar() :: json_boolean() | json_number() | json_string().
 
--type float_format_option() :: {scientific, Decimals :: 0 .. 249} | {decimals, Decimals :: 0 .. 253} | compact.
+-type float_format_option() :: {scientific, Decimals :: 0..249} | {decimals, Decimals :: 0..253} | compact.
 %% `scientific': <br />
 %% - The float will be formatted using scientific notation with `Decimals' digits of precision. <br />
 %%
@@ -184,7 +184,7 @@
 
 -type datetime_format() :: iso8601.
 -type timezone() :: utc | local | utc_offset_seconds().
--type utc_offset_seconds() :: -86399 .. 86399.
+-type utc_offset_seconds() :: -86399..86399.
 
 -type common_option() :: undefined_as_null.
 %%

+ 5 - 10
src/jsone_decode.erl

@@ -190,6 +190,7 @@ object_value(<<$:, Bin/binary>>, Key, Members, Nexts, Buf, Opt) ->
 object_value(Bin, Key, Members, Nexts, Buf, Opt) ->
     ?ERROR(object_value, [Bin, Key, Members, Nexts, Buf, Opt]).
 
+
 -compile({inline, [object_key/2]}).
 
 
@@ -271,16 +272,12 @@ string(Bin, Base, Start, Nexts, Buf, Opt) ->
 
 -spec unicode_string(binary(), non_neg_integer(), [next()], binary(), opt()) -> decode_result().
 unicode_string(<<N:4/binary, Bin/binary>>, Start, Nexts, Buf, Opt) ->
-    try
-        binary_to_integer(N, 16)
-    of
+    try binary_to_integer(N, 16) of
         High when 16#D800 =< High, High =< 16#DBFF ->
             %% surrogate pair
             case Bin of
                 <<$\\, $u, N2:4/binary, Bin2/binary>> ->
-                    try
-                        binary_to_integer(N2, 16)
-                    of
+                    try binary_to_integer(N2, 16) of
                         Low when 16#DC00 =< Low, Low =< 16#DFFF ->
                             <<Unicode/utf16>> = <<High:16, Low:16>>,
                             string(Bin2, Start, Nexts, <<Buf/binary, Unicode/utf8>>, Opt);
@@ -383,14 +380,12 @@ number_exponation_part(<<C, Bin/binary>>, N, DecimalOffset, ExpSign, Exp, _, Nex
     number_exponation_part(Bin, N, DecimalOffset, ExpSign, Exp * 10 + C - $0, false, Nexts, Buf, Opt);
 number_exponation_part(<<Bin/binary>>, N, DecimalOffset, ExpSign, Exp, false, Nexts, Buf, Opt) ->
     Pos = ExpSign * Exp - DecimalOffset,
-    try
-        case Pos of
+    try case Pos of
             Pos when Pos >= 0 ->
                 N * math:pow(10, Pos);
             _ ->
                 N / math:pow(10, -Pos)  % multiplying by decimal makes float errors larger.
-        end
-    of
+        end of
         Res ->
             next(Bin, Res, Nexts, Buf, Opt)
     catch

+ 7 - 4
src/jsone_encode.erl

@@ -139,9 +139,7 @@ value({{json, T}}, Nexts, Buf, Opt) ->
             ?ERROR(value, [{json, T}, Nexts, Buf, Opt])
     end;
 value({{json_utf8, T}}, Nexts, Buf, Opt) ->
-    try
-        unicode:characters_to_binary(T)
-    of
+    try unicode:characters_to_binary(T) of
         {error, OK, Invalid} ->
             {error, {{invalid_json_utf8, OK, Invalid},
                      [{?MODULE, value, [{json_utf8, T}, Nexts, Buf, Opt], [{line, ?LINE}]}]}};
@@ -213,6 +211,7 @@ datetime({{Y, M, D}, {H, Mi, S}}, Nexts, Buf, Opt) when ?IS_DATETIME(Y, M, D, H,
 datetime(Datetime, Nexts, Buf, Opt) ->
     ?ERROR(datetime, [Datetime, Nexts, Buf, Opt]).
 
+
 -ifndef(NO_DIALYZER_SPEC).
 -dialyzer({no_improper_lists, [format_year/1]}).
 -endif.
@@ -266,6 +265,7 @@ format_tz(Tz) when Tz > 0 ->
 format_tz(Tz) ->
     [$- | format_tz_(-Tz)].
 
+
 -define(SECONDS_PER_MINUTE, 60).
 -define(SECONDS_PER_HOUR,   3600).
 
@@ -296,6 +296,7 @@ object_key(Key, Nexts, Buf, Opt = ?OPT{object_key_type = value}) ->
 object_key(Key, Nexts, Buf, Opt) ->
     ?ERROR(object_key, [Key, Nexts, Buf, Opt]).
 
+
 -define(H8(X), (hex(X)):16).
 -define(H16(X), ?H8(X bsr 8), ?H8(X band 16#FF)).
 
@@ -355,6 +356,7 @@ escape_string(<<Ch/utf8, Str/binary>>, Nexts, Buf, Opt = ?OPT{native_utf8 = fals
 escape_string(Str, Nexts, Buf, Opt) ->
     ?ERROR(escape_string, [Str, Nexts, Buf, Opt]).
 
+
 -define(UNESCAPED_CHARS_WITH_SLASH,
         {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false,
                 false, false, false, false, false, false, false, false, false, false, false, false, false, false, false,
@@ -414,10 +416,11 @@ unescaped_string_length(<<C, Str/binary>>, N, Table) ->
 unescaped_string_length(_, N, _) ->
     N.
 
+
 -compile({inline, [hex/1]}).
 
 
--spec hex(byte()) -> 0 .. 16#FFFF.
+-spec hex(byte()) -> 0..16#FFFF.
 hex(X) ->
     element(X + 1,
             {16#3030, 16#3031, 16#3032, 16#3033, 16#3034, 16#3035, 16#3036, 16#3037, 16#3038, 16#3039, 16#3061, 16#3062,

+ 4 - 4
src/jsone_inet.erl

@@ -44,11 +44,11 @@
         ?IS_IPV6_RANGE(A) andalso ?IS_IPV6_RANGE(B) andalso ?IS_IPV6_RANGE(C) andalso ?IS_IPV6_RANGE(D) andalso
         ?IS_IPV6_RANGE(E) andalso ?IS_IPV6_RANGE(F) andalso ?IS_IPV6_RANGE(G) andalso ?IS_IPV6_RANGE(H)).
 
-
 %%--------------------------------------------------------------------------------
 %% Exported Functions
 %%--------------------------------------------------------------------------------
 
+
 %% @doc Convert an IP address into a text representation.
 %%
 %% Please refer to the doc of `jsone:ip_address_to_json_string/1' for the detail.
@@ -86,7 +86,7 @@ ip_address_to_json_string(_) ->
 %%--------------------------------------------------------------------------------
 %% Internal Functions
 %%--------------------------------------------------------------------------------
--spec format_ipv6([0 .. 65535]) -> string().
+-spec format_ipv6([0..65535]) -> string().
 format_ipv6(Xs) ->
     case format_ipv6(Xs, 0, 0) of
         {Ys, shortening} ->
@@ -102,7 +102,7 @@ format_ipv6(Xs) ->
     end.
 
 
--spec format_ipv6([0 .. 65535], non_neg_integer(), non_neg_integer()) ->
+-spec format_ipv6([0..65535], non_neg_integer(), non_neg_integer()) ->
           {[string()], not_shortened | shortening | shortened}.
 format_ipv6([], _Zeros, _MaxZeros) ->
     {[], not_shortened};
@@ -130,6 +130,6 @@ format_ipv6([X | Xs], Zeros0, MaxZeros) ->
     end.
 
 
--spec to_hex(0 .. 65535) -> string().
+-spec to_hex(0..65535) -> string().
 to_hex(N) ->
     string:lowercase(integer_to_list(N, 16)).

+ 10 - 10
test/jsone_decode_tests.erl

@@ -12,7 +12,7 @@
 -define(OBJ2_DUP_KEY(K1, V1, K2, V2), ?OBJ2(K1, V1, K2, V2)).
 -else.
 -define(MAP_OBJECT_TYPE, map).
--define(OBJ0, #{}).
+-define(OBJ0,            #{}).
 -define(OBJ1(K, V), #{K => V}).
 -define(OBJ2(K1, V1, K2, V2), #{K1 => V1, K2 => V2}).
 -define(OBJ2_DUP_KEY(K1, V1, _K2, _V2), #{K1 => V1}).  % the first (leftmost) value is used
@@ -33,8 +33,8 @@ decode_test_() ->
      {"negative integer", fun() -> ?assertEqual({ok, -1, <<"">>}, jsone_decode:decode(<<"-1">>)) end},
      {"large integer (no limit on size)",
       fun() ->
-             ?assertEqual({ok, 111111111111111111111111111111111111111111111111111111111111111111111111111111, <<"">>},
-                          jsone_decode:decode(<<"111111111111111111111111111111111111111111111111111111111111111111111111111111">>))
+              ?assertEqual({ok, 111111111111111111111111111111111111111111111111111111111111111111111111111111, <<"">>},
+                           jsone_decode:decode(<<"111111111111111111111111111111111111111111111111111111111111111111111111111111">>))
       end},
      {"integer with leading zero (interpreted as zero and remaining binary)",
       fun() ->
@@ -77,7 +77,7 @@ decode_test_() ->
      {"simple string", fun() -> ?assertEqual({ok, <<"abc">>, <<"">>}, jsone_decode:decode(<<"\"abc\"">>)) end},
      {"string: escaped characters",
       fun() ->
-              Input = list_to_binary([$", [[$\\, C] || C <- [$", $/, $\\, $b, $f, $n, $r, $t]], $"]),
+              Input = list_to_binary([$", [ [$\\, C] || C <- [$", $/, $\\, $b, $f, $n, $r, $t] ], $"]),
               Expected = <<"\"\/\\\b\f\n\r\t">>,
               ?assertEqual({ok, Expected, <<"">>}, jsone_decode:decode(Input))
       end},
@@ -113,14 +113,14 @@ decode_test_() ->
       fun() ->
               Ctrls = lists:seq(0, 16#1f),
               lists:foreach(fun(C) ->
-                                   %% Control characters are unacceptable
-                                   ?assertMatch({error, {badarg, _}}, jsone_decode:decode(<<$", C, $">>))
+                                    %% Control characters are unacceptable
+                                    ?assertMatch({error, {badarg, _}}, jsone_decode:decode(<<$", C, $">>))
                             end,
                             Ctrls),
               lists:foreach(fun(C) ->
-                                   %% `allow_ctrl_chars' option allows strings which contain unescaped control characters
-                                   ?assertEqual({ok, <<C>>, <<"">>},
-                                                jsone_decode:decode(<<$", C, $">>, [{allow_ctrl_chars, true}]))
+                                    %% `allow_ctrl_chars' option allows strings which contain unescaped control characters
+                                    ?assertEqual({ok, <<C>>, <<"">>},
+                                                 jsone_decode:decode(<<$", C, $">>, [{allow_ctrl_chars, true}]))
                             end,
                             Ctrls)
       end},
@@ -200,7 +200,7 @@ decode_test_() ->
       end},
      {"empty object: map",
       fun() ->
-             ?assertEqual({ok, ?OBJ0, <<"">>}, jsone_decode:decode(<<"{}">>, [{object_format, ?MAP_OBJECT_TYPE}]))
+              ?assertEqual({ok, ?OBJ0, <<"">>}, jsone_decode:decode(<<"{}">>, [{object_format, ?MAP_OBJECT_TYPE}]))
       end},
      {"duplicated members: map",
       fun() ->

+ 6 - 6
test/jsone_encode_tests.erl

@@ -46,8 +46,8 @@ encode_test_() ->
      {"negative integer", fun() -> ?assertEqual({ok, <<"-1">>}, jsone_encode:encode(-1)) end},
      {"large number",
       fun() ->
-             ?assertEqual({ok, <<"11111111111111111111111111111111111111111111111111111111111111111111111">>},
-                          jsone_encode:encode(11111111111111111111111111111111111111111111111111111111111111111111111))
+              ?assertEqual({ok, <<"11111111111111111111111111111111111111111111111111111111111111111111111">>},
+                           jsone_encode:encode(11111111111111111111111111111111111111111111111111111111111111111111111))
       end},
 
      %% Numbers: Float",
@@ -73,7 +73,7 @@ encode_test_() ->
      {"string: contains escaped characters",
       fun() ->
               Input = <<"\"\/\\\b\f\n\r\t">>,
-              Expected = list_to_binary([$", [[$\\, C] || C <- [$", $/, $\\, $b, $f, $n, $r, $t]], $"]),
+              Expected = list_to_binary([$", [ [$\\, C] || C <- [$", $/, $\\, $b, $f, $n, $r, $t] ], $"]),
               ?assertEqual({ok, Expected}, jsone_encode:encode(Input)),
               ?assertEqual({ok, Expected}, jsone_encode:encode(Input, [native_utf8]))
       end},
@@ -87,7 +87,7 @@ encode_test_() ->
       fun() ->
               Ctrls = lists:seq(16#00, 16#1F) -- [$\b, $\f, $\n, $\r, $\t],
               Input = list_to_binary(Ctrls),
-              Expected = list_to_binary([$", [io_lib:format("\\u00~2.16.0b", [C]) || C <- Ctrls], $"]),
+              Expected = list_to_binary([$", [ io_lib:format("\\u00~2.16.0b", [C]) || C <- Ctrls ], $"]),
               ?assertEqual({ok, Expected}, jsone_encode:encode(Input)),
               ?assertEqual({ok, Expected}, jsone_encode:encode(Input, [native_utf8]))
       end},
@@ -342,7 +342,7 @@ encode_test_() ->
      {"wrong option", fun() -> ?assertError(badarg, jsone_encode:encode(1, [{no_such_option, hoge}])) end},
      {"canonical_form",
       fun() ->
-              Obj1 = ?OBJECT_FROM_LIST([{<<"key", (integer_to_binary(I))/binary>>, I} || I <- lists:seq(1000, 0, -1)]),
-              Obj2 = ?OBJECT_FROM_LIST([{<<"key", (integer_to_binary(I))/binary>>, I} || I <- lists:seq(0, 1000, 1)]),
+              Obj1 = ?OBJECT_FROM_LIST([ {<<"key", (integer_to_binary(I))/binary>>, I} || I <- lists:seq(1000, 0, -1) ]),
+              Obj2 = ?OBJECT_FROM_LIST([ {<<"key", (integer_to_binary(I))/binary>>, I} || I <- lists:seq(0, 1000, 1) ]),
               ?assertEqual(jsone_encode:encode(Obj1, [canonical_form]), jsone_encode:encode(Obj2, [canonical_form]))
       end}].