From 353fc0f82f0a23c17b9c603c3113812708dd2eda Mon Sep 17 00:00:00 2001 From: voluntas Date: Sat, 22 Jun 2024 14:34:05 +0900 Subject: [PATCH] =?UTF-8?q?elvis=20=E9=80=9A=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- elvis.config | 4 ++++ src/jesse_json_path.erl | 14 +++++++------- src/jesse_state.erl | 2 +- src/jesse_validator_draft6.erl | 12 ++++++------ 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/elvis.config b/elvis.config index a94ce777..e8428318 100644 --- a/elvis.config +++ b/elvis.config @@ -21,6 +21,10 @@ {elvis_style, export_used_types, disable}, {elvis_style, private_data_types, disable}, %% 要検討 + {elvis_style, no_debug_call, disable}, + %% 要検討 + {elvis_style, no_throw, disable}, + %% 要検討 {elvis_style, no_single_clause_case, disable}, %% 要検討 {elvis_style, max_function_arity, disable}, diff --git a/src/jesse_json_path.erl b/src/jesse_json_path.erl index f8762f1e..2a8793b7 100644 --- a/src/jesse_json_path.erl +++ b/src/jesse_json_path.erl @@ -45,7 +45,7 @@ path(Path, P, Default) when is_binary(Path) -> path(binary:split(Path, <<".">>, [global]), P, Default); path(Path, P, Default) when is_atom(Path) -> path(atom_to_binary(Path, utf8), P, Default); -path(Path = [N | _], P, Default) when is_integer(N) -> +path([N | _] = Path, P, Default) when is_integer(N) -> path(iolist_to_binary(Path), P, Default); path([], [], Default) -> Default; @@ -108,12 +108,12 @@ to_proplist([]) -> []; to_proplist([{}]) -> []; -to_proplist(L = [{struct, _} | _]) -> +to_proplist([{struct, _} | _] = L) -> to_proplist_l(L); -to_proplist(L = [{K, _} | _]) when not is_integer(K) -> +to_proplist([{K, _} | _] = L) when not is_integer(K) -> %% gb_trees is an {integer(), _} to_proplist_pl(L); -to_proplist(L = [_ | _]) -> +to_proplist([_ | _] = L) -> first_of( [fun to_proplist_gb_l/1, fun to_proplist_pl/1, @@ -151,7 +151,7 @@ to_proplist_l(L) -> [ to_proplist(V) || V <- L ]. -to_proplist_pl(L = [{_, _} | _]) -> +to_proplist_pl([{_, _} | _] = L) -> [ {K, to_proplist(V)} || {K, V} <- L ]; to_proplist_pl([]) -> []. @@ -199,7 +199,7 @@ get_nested_values(<<"@unionOfObjects">>, L, _R) -> L; get_nested_values(A, L, R) when is_atom(A) andalso A > '@' andalso A < 'A' -> get_nested_values(atom_to_binary(A, utf8), L, R); -get_nested_values(K = "@" ++ _, L, R) -> +get_nested_values("@" ++ _ = K, L, R) -> get_nested_values(iolist_to_binary(K), L, R); get_nested_values(K, [L | Rest], R) -> case value(K, L, R) of @@ -213,7 +213,7 @@ get_nested_values(_K, [], _R) -> -spec proplist_type(term()) -> typed_proplist(). -proplist_type(P = [{K, _} | _]) -> +proplist_type([{K, _} | _] = P) -> {P, typeof_elem(K)}; proplist_type({struct, P = [{K, _} | _]}) -> {P, typeof_elem(K)}; diff --git a/src/jesse_state.erl b/src/jesse_state.erl index 788c9a0a..d5bb5af0 100644 --- a/src/jesse_state.erl +++ b/src/jesse_state.erl @@ -161,7 +161,7 @@ new(JsonSchema, Options) -> %% @doc Removes the last element from `current_path' in `State'. -spec remove_last_from_path(State :: state()) -> state(). -remove_last_from_path(State = #state{current_path = [_Property | Path]}) -> +remove_last_from_path(#state{current_path = [_Property | Path]} = State) -> State#state{current_path = Path}. diff --git a/src/jesse_validator_draft6.erl b/src/jesse_validator_draft6.erl index 7f19c9bd..e7e97df0 100644 --- a/src/jesse_validator_draft6.erl +++ b/src/jesse_validator_draft6.erl @@ -940,32 +940,32 @@ check_enum(Value, Enum, State) -> %% @doc format %% Used for semantic validation. %% @private -check_format(Value, _Format = <<"date-time">>, State) when is_binary(Value) -> +check_format(Value, <<"date-time">> = _Format, State) when is_binary(Value) -> case valid_datetime(Value) of true -> State; false -> handle_data_invalid(?wrong_format, Value, State) end; -check_format(Value, _Format = <<"email">>, State) when is_binary(Value) -> +check_format(Value, <<"email">> = _Format, State) when is_binary(Value) -> case jesse_lib:re_run(Value, <<"^[^@]+@[^@]+$">>) of match -> State; nomatch -> handle_data_invalid(?wrong_format, Value, State) end; -check_format(Value, _Format = <<"hostname">>, State) when is_binary(Value) -> +check_format(Value, <<"hostname">> = _Format, State) when is_binary(Value) -> %% not yet supported State; -check_format(Value, _Format = <<"ipv4">>, State) when is_binary(Value) -> +check_format(Value, <<"ipv4">> = _Format, State) when is_binary(Value) -> %% avoiding inet:parse_ipv4strict_address to maintain R15 compatibility case inet_parse:ipv4strict_address(binary_to_list(Value)) of {ok, _IPv4Address} -> State; {error, einval} -> handle_data_invalid(?wrong_format, Value, State) end; -check_format(Value, _Format = <<"ipv6">>, State) when is_binary(Value) -> +check_format(Value, <<"ipv6">> = _Format, State) when is_binary(Value) -> %% avoiding inet:parse_ipv6strict_address to maintain R15 compatibility case inet_parse:ipv6strict_address(binary_to_list(Value)) of {ok, _IPv6Address} -> State; {error, einval} -> handle_data_invalid(?wrong_format, Value, State) end; -check_format(Value, _Format = <<"uri">>, State) when is_binary(Value) -> +check_format(Value, <<"uri">> = _Format, State) when is_binary(Value) -> %% not yet supported State; check_format(Value, <<"uri-reference">>, State) when is_binary(Value) ->