Skip to content

Commit 217e9a6

Browse files
authored
Fixes missing Erlang ruleset in linter and addresses minor warnings (#179)
1 parent f67ad51 commit 217e9a6

32 files changed

Lines changed: 250 additions & 240 deletions

apps/hellgate/src/hellgate.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ construct_health_routes(readiness, Check) ->
9090

9191
enable_health_logging(Check) ->
9292
EvHandler = {erl_health_event_handler, []},
93-
maps:map(fun(_, V = {_, _, _}) -> #{runner => V, event_handler => EvHandler} end, Check).
93+
maps:map(fun(_, {_, _, _} = V) -> #{runner => V, event_handler => EvHandler} end, Check).
9494

9595
construct_service_handler(Name, Module, Opts) ->
9696
FullOpts = maps:merge(#{handler => Module}, Opts),

apps/hellgate/src/hg_allocation.erl

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,21 @@
5454
-spec calculate(allocation_prototype(), party(), shop(), cash(), allocation_terms()) ->
5555
{error, calculate_errors()}.
5656
calculate(AllocationPrototype, Party, Shop, Cost, PaymentAllocationServiceTerms) ->
57-
case assert_allocatable(AllocationPrototype, PaymentAllocationServiceTerms, Party, Shop, Cost) of
58-
% ok ->
59-
% try calculate(AllocationPrototype, Party#domain_PartyConfig.id, Shop#domain_ShopConfig.id, Cost) of
60-
% Result ->
61-
% {ok, Result}
62-
% catch
63-
% throw:Error ->
64-
% {error, Error}
65-
% end;
66-
{error, Error} ->
67-
{error, Error}
68-
end.
57+
%% NOTE Allocation is temporarily disabled.
58+
%% case assert_allocatable(AllocationPrototype, PaymentAllocationServiceTerms, Party, Shop, Cost) of
59+
%% ok ->
60+
%% try calculate(AllocationPrototype, Party#domain_PartyConfig.id, Shop#domain_ShopConfig.id, Cost) of
61+
%% Result ->
62+
%% {ok, Result}
63+
%% catch
64+
%% throw:Error ->
65+
%% {error, Error}
66+
%% end;
67+
%% {error, Error} ->
68+
%% {error, Error}
69+
%% end.
70+
{error, Error} = assert_allocatable(AllocationPrototype, PaymentAllocationServiceTerms, Party, Shop, Cost),
71+
{error, Error}.
6972

7073
-spec sub(allocation(), allocation()) -> {ok, allocation()} | {error, sub_errors()}.
7174
sub(Allocation, SubAllocation) ->

apps/hellgate/src/hg_cashflow.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ compute_volume(?product(Fun, CVs) = CV0, Context) ->
164164
error({misconfiguration, {'Cash volume product over empty set', CV0}})
165165
end.
166166

167-
compute_parts_of(P, Q, Cash = #domain_Cash{amount = Amount}, RoundingMethod) ->
167+
compute_parts_of(P, Q, #domain_Cash{amount = Amount} = Cash, RoundingMethod) ->
168168
Cash#domain_Cash{
169169
amount = genlib_rational:round(
170170
genlib_rational:mul(
@@ -182,7 +182,7 @@ compute_product(Fun, [CV | CVRest], CV0, Context) ->
182182
CVRest
183183
).
184184

185-
compute_product(Fun, CV, CVMin = #domain_Cash{amount = AmountMin, currency = Currency}, CV0, Context) ->
185+
compute_product(Fun, CV, #domain_Cash{amount = AmountMin, currency = Currency} = CVMin, CV0, Context) ->
186186
case compute_volume(CV, Context) of
187187
#domain_Cash{amount = Amount, currency = Currency} ->
188188
CVMin#domain_Cash{amount = compute_product_fun(Fun, AmountMin, Amount)};

apps/hellgate/src/hg_cashflow_utils.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ collect_allocation_cash_flow(
9494
construct_transaction_cashflow(
9595
Amount,
9696
PaymentInstitution,
97-
Context = #{
97+
#{
9898
revision := Revision,
9999
operation := OpType,
100100
shop := {_, Shop},
101101
varset := VS
102-
}
102+
} = Context
103103
) ->
104104
MerchantPaymentsTerms1 =
105105
case maps:get(merchant_terms, Context, undefined) of
@@ -114,7 +114,7 @@ construct_transaction_cashflow(
114114
AccountMap = hg_accounting:collect_account_map(make_collect_account_context(PaymentInstitution, Context)),
115115
construct_final_cashflow(MerchantCashflow, #{operation_amount => Amount}, AccountMap).
116116

117-
construct_provider_cashflow(PaymentInstitution, Context = #{provision_terms := ProvisionTerms}) ->
117+
construct_provider_cashflow(PaymentInstitution, #{provision_terms := ProvisionTerms} = Context) ->
118118
ProviderCashflowSelector = get_provider_cashflow_selector(ProvisionTerms),
119119
ProviderCashflow = get_selector_value(provider_payment_cash_flow, ProviderCashflowSelector),
120120
AccountMap = hg_accounting:collect_account_map(make_collect_account_context(PaymentInstitution, Context)),

apps/hellgate/src/hg_datetime.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
%%
3535

3636
-spec format_dt(datetime()) -> timestamp().
37-
format_dt(Dt = {_, _}) ->
37+
format_dt({_, _} = Dt) ->
3838
Ts = genlib_time:daytime_to_unixtime(Dt),
3939
format_ts(Ts).
4040

apps/hellgate/src/hg_fault_detector_client.erl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89,24 +89,24 @@ build_operation_id(ServiceType, IDs) ->
8989
hg_utils:construct_complex_id(lists:flatten([<<"hellgate_operation">>, genlib:to_binary(ServiceType), MappedIDs])).
9090

9191
-spec init_service(service_id(), service_config()) -> {ok, initialised} | {error, any()} | disabled.
92-
init_service(ServiceId, ServiceConfig) ->
93-
call('InitService', {ServiceId, ServiceConfig}).
92+
init_service(ServiceID, ServiceConfig) ->
93+
call('InitService', {ServiceID, ServiceConfig}).
9494

9595
-spec get_statistics([service_id()]) -> [service_stats()].
96-
get_statistics(ServiceIds) when is_list(ServiceIds) ->
97-
call('GetStatistics', {ServiceIds}).
96+
get_statistics(ServiceIDs) when is_list(ServiceIDs) ->
97+
call('GetStatistics', {ServiceIDs}).
9898

9999
-spec register_operation(operation_status(), service_id(), operation_id(), service_config()) ->
100100
{ok, registered} | {error, not_found} | {error, any()} | disabled.
101-
register_operation(Status, ServiceId, OperationId, ServiceConfig) ->
101+
register_operation(Status, ServiceID, OperationID, ServiceConfig) ->
102102
OperationState =
103103
case Status of
104104
start -> {Status, ?state_start(hg_datetime:format_now())};
105105
error -> {Status, ?state_error(hg_datetime:format_now())};
106106
finish -> {Status, ?state_finish(hg_datetime:format_now())}
107107
end,
108-
Operation = ?operation(OperationId, OperationState),
109-
call('RegisterOperation', {ServiceId, Operation, ServiceConfig}).
108+
Operation = ?operation(OperationID, OperationState),
109+
call('RegisterOperation', {ServiceID, Operation, ServiceConfig}).
110110

111111
%% PRIVATE
112112

@@ -125,7 +125,7 @@ maybe_call(false = _FDEnabled, 'GetStatistics', _Args, _Opts, _Deadline) ->
125125
maybe_call(false = _FDEnabled, _Service, _Args, _Opts, _Deadline) ->
126126
disabled.
127127

128-
do_call('InitService', {ServiceId, _ServiceConfig} = Args, Opts, Deadline) ->
128+
do_call('InitService', {ServiceID, _ServiceConfig} = Args, Opts, Deadline) ->
129129
try hg_woody_wrapper:call(fault_detector, 'InitService', Args, Opts, Deadline) of
130130
{ok, _Result} -> {ok, initialised}
131131
catch
@@ -134,14 +134,14 @@ do_call('InitService', {ServiceId, _ServiceConfig} = Args, Opts, Deadline) ->
134134
Class =:= result_unknown
135135
->
136136
ErrorText = "Unable to init service ~p in fault detector, ~p:~p",
137-
_ = logger:warning(ErrorText, [ServiceId, error, Reason]),
137+
_ = logger:warning(ErrorText, [ServiceID, error, Reason]),
138138
{error, Reason};
139139
error:{woody_error, {_Source, result_unexpected, _Details}} = Reason ->
140140
ErrorText = "Unable to init service ~p in fault detector, ~p:~p",
141-
_ = logger:error(ErrorText, [ServiceId, error, Reason]),
141+
_ = logger:error(ErrorText, [ServiceID, error, Reason]),
142142
{error, Reason}
143143
end;
144-
do_call('GetStatistics', {ServiceIds} = Args, Opts, Deadline) ->
144+
do_call('GetStatistics', {ServiceIDs} = Args, Opts, Deadline) ->
145145
try hg_woody_wrapper:call(fault_detector, 'GetStatistics', Args, Opts, Deadline) of
146146
{ok, Stats} -> Stats
147147
catch
@@ -150,14 +150,14 @@ do_call('GetStatistics', {ServiceIds} = Args, Opts, Deadline) ->
150150
Class =:= result_unknown
151151
->
152152
String = "Unable to get statistics for services ~p from fault detector, ~p:~p",
153-
_ = logger:warning(String, [ServiceIds, error, Reason]),
153+
_ = logger:warning(String, [ServiceIDs, error, Reason]),
154154
[];
155155
error:{woody_error, {_Source, result_unexpected, _Details}} = Reason ->
156156
String = "Unable to get statistics for services ~p from fault detector, ~p:~p",
157-
_ = logger:error(String, [ServiceIds, error, Reason]),
157+
_ = logger:error(String, [ServiceIDs, error, Reason]),
158158
[]
159159
end;
160-
do_call('RegisterOperation', {ServiceId, OperationId, _ServiceConfig} = Args, Opts, Deadline) ->
160+
do_call('RegisterOperation', {ServiceID, OperationID, _ServiceConfig} = Args, Opts, Deadline) ->
161161
try hg_woody_wrapper:call(fault_detector, 'RegisterOperation', Args, Opts, Deadline) of
162162
{ok, _Result} ->
163163
{ok, registered};
@@ -169,10 +169,10 @@ do_call('RegisterOperation', {ServiceId, OperationId, _ServiceConfig} = Args, Op
169169
Class =:= result_unknown
170170
->
171171
ErrorText = "Unable to register operation ~p for service ~p in fault detector, ~p:~p",
172-
_ = logger:warning(ErrorText, [OperationId, ServiceId, error, Reason]),
172+
_ = logger:warning(ErrorText, [OperationID, ServiceID, error, Reason]),
173173
{error, Reason};
174174
error:{woody_error, {_Source, result_unexpected, _Details}} = Reason ->
175175
ErrorText = "Unable to register operation ~p for service ~p in fault detector, ~p:~p",
176-
_ = logger:error(ErrorText, [OperationId, ServiceId, error, Reason]),
176+
_ = logger:error(ErrorText, [OperationID, ServiceID, error, Reason]),
177177
{error, Reason}
178178
end.

apps/hellgate/src/hg_inspector.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ inspect(
100100
RiskScore.
101101

102102
get_payment_info(
103-
Shop = #domain_ShopConfig{
103+
#domain_ShopConfig{
104104
category = CategoryRef,
105105
location = Location
106-
},
106+
} = Shop,
107107
#domain_Invoice{
108108
party_ref = PartyConfigRef,
109109
shop_ref = ShopConfigRef,

apps/hellgate/src/hg_invoice.erl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@
9090
%% API
9191

9292
-spec get(hg_machine:id()) -> {ok, st()} | {error, notfound}.
93-
get(Id) ->
94-
case hg_machine:get_history(?NS, Id) of
93+
get(ID) ->
94+
case hg_machine:get_history(?NS, ID) of
9595
{ok, History} ->
9696
{ok, collapse_history(unmarshal_history(History))};
9797
Error ->
@@ -108,7 +108,7 @@ get_payment(PaymentID, St) ->
108108
end.
109109

110110
-spec get_payment_opts(st()) -> hg_invoice_payment:opts().
111-
get_payment_opts(St = #st{invoice = Invoice, party = undefined}) ->
111+
get_payment_opts(#st{invoice = Invoice, party = undefined} = St) ->
112112
{PartyConfigRef, Party} = hg_party:get_party(get_party_config_ref(St)),
113113
#{
114114
party => Party,
@@ -126,7 +126,7 @@ get_payment_opts(#st{invoice = Invoice, party = Party, party_config_ref = PartyC
126126

127127
-spec get_payment_opts(hg_domain:revision(), st()) ->
128128
hg_invoice_payment:opts().
129-
get_payment_opts(Revision, St = #st{invoice = Invoice}) ->
129+
get_payment_opts(Revision, #st{invoice = Invoice} = St) ->
130130
{PartyConfigRef, Party} = hg_party:checkout(get_party_config_ref(St), Revision),
131131
#{
132132
party => Party,
@@ -144,7 +144,7 @@ get_payment_opts(Revision, St = #st{invoice = Invoice}) ->
144144
revision()
145145
) ->
146146
invoice().
147-
create(ID, InvoiceTplID, V = #payproc_InvoiceParams{}, _Allocation, Mutations, DomainRevision) ->
147+
create(ID, InvoiceTplID, #payproc_InvoiceParams{} = V, _Allocation, Mutations, DomainRevision) ->
148148
PartyConfigRef = V#payproc_InvoiceParams.party_id,
149149
ShopConfigRef = V#payproc_InvoiceParams.shop_id,
150150
Cost = V#payproc_InvoiceParams.cost,
@@ -262,8 +262,8 @@ process_with_tag(Tag, F) ->
262262
%%
263263

264264
-spec fail(hg_machine:id()) -> ok.
265-
fail(Id) ->
266-
try hg_machine:call(?NS, Id, fail) of
265+
fail(ID) ->
266+
try hg_machine:call(?NS, ID, fail) of
267267
{error, failed} ->
268268
ok;
269269
{error, Error} ->
@@ -315,7 +315,7 @@ handle_repair({changes, Changes, RepairAction, Params}, St) ->
315315
};
316316
handle_repair({scenario, _}, #st{activity = Activity}) when Activity =:= invoice orelse Activity =:= undefined ->
317317
throw({exception, invoice_has_no_active_payment});
318-
handle_repair({scenario, Scenario}, St = #st{activity = {payment, PaymentID}}) ->
318+
handle_repair({scenario, Scenario}, #st{activity = {payment, PaymentID}} = St) ->
319319
PaymentSession = get_payment_session(PaymentID, St),
320320
Activity = hg_invoice_payment:get_activity(PaymentSession),
321321
case {Scenario, Activity} of
@@ -329,11 +329,11 @@ handle_repair({scenario, Scenario}, St = #st{activity = {payment, PaymentID}}) -
329329
process_signal(Signal, #{history := History}) ->
330330
handle_result(handle_signal(Signal, collapse_history(unmarshal_history(History)))).
331331

332-
handle_signal(timeout, St = #st{activity = {payment, PaymentID}}) ->
332+
handle_signal(timeout, #st{activity = {payment, PaymentID}} = St) ->
333333
% there's a payment pending
334334
PaymentSession = get_payment_session(PaymentID, St),
335335
process_payment_signal(timeout, PaymentID, PaymentSession, St);
336-
handle_signal(timeout, St = #st{activity = invoice}) ->
336+
handle_signal(timeout, #st{activity = invoice} = St) ->
337337
% invoice is expired
338338
handle_expiration(St).
339339

@@ -493,10 +493,10 @@ handle_call({session_change, _Tag, _SessionChange} = Call, St) ->
493493

494494
-spec dispatch_to_session({callback, tag(), callback()} | {session_change, tag(), session_change()}, st()) ->
495495
call_result().
496-
dispatch_to_session({callback, Tag, {provider, Payload}}, St = #st{activity = {payment, PaymentID}}) ->
496+
dispatch_to_session({callback, Tag, {provider, Payload}}, #st{activity = {payment, PaymentID}} = St) ->
497497
PaymentSession = get_payment_session(PaymentID, St),
498498
process_payment_call({callback, Tag, Payload}, PaymentID, PaymentSession, St);
499-
dispatch_to_session({session_change, _Tag, _SessionChange} = Call, St = #st{activity = {payment, PaymentID}}) ->
499+
dispatch_to_session({session_change, _Tag, _SessionChange} = Call, #st{activity = {payment, PaymentID}} = St) ->
500500
PaymentSession = get_payment_session(PaymentID, St),
501501
process_payment_call(Call, PaymentID, PaymentSession, St);
502502
dispatch_to_session(_Call, _St) ->
@@ -733,7 +733,7 @@ define_refund_id(#payproc_InvoicePaymentRefundParams{id = ID}, _PaymentSession)
733733
-define(MANUAL_REFUND_ID_PREFIX, "m").
734734

735735
%% If something breaks - this is why
736-
force_refund_id_format(manual_refund, Correct = <<?MANUAL_REFUND_ID_PREFIX, _Rest/binary>>) ->
736+
force_refund_id_format(manual_refund, <<?MANUAL_REFUND_ID_PREFIX, _Rest/binary>> = Correct) ->
737737
Correct;
738738
force_refund_id_format(manual_refund, Incorrect) ->
739739
<<?MANUAL_REFUND_ID_PREFIX, Incorrect/binary>>;
@@ -816,7 +816,7 @@ try_to_get_repair_state({complex, #payproc_InvoiceRepairComplex{scenarios = Scen
816816
try_to_get_repair_state(Scenario, St) ->
817817
repair_scenario(Scenario, St).
818818

819-
repair_complex([], St = #st{activity = {payment, PaymentID}}) ->
819+
repair_complex([], #st{activity = {payment, PaymentID}} = St) ->
820820
PaymentSession = get_payment_session(PaymentID, St),
821821
Activity = hg_invoice_payment:get_activity(PaymentSession),
822822
throw({exception, {activity_not_compatible_with_complex_scenario, Activity}});
@@ -828,7 +828,7 @@ repair_complex([Scenario | Rest], St) ->
828828
repair_complex(Rest, St)
829829
end.
830830

831-
repair_scenario(Scenario, St = #st{activity = {payment, PaymentID}}) ->
831+
repair_scenario(Scenario, #st{activity = {payment, PaymentID}} = St) ->
832832
PaymentSession = get_payment_session(PaymentID, St),
833833
Activity = hg_invoice_payment:get_activity(PaymentSession),
834834
NewActivity =
@@ -923,7 +923,7 @@ try_get_payment_session(PaymentID, #st{payments = Payments}) ->
923923
undefined
924924
end.
925925

926-
set_payment_session(PaymentID, PaymentSession, St = #st{payments = Payments}) ->
926+
set_payment_session(PaymentID, PaymentSession, #st{payments = Payments} = St) ->
927927
St#st{payments = lists:keystore(PaymentID, 1, Payments, {PaymentID, PaymentSession})}.
928928

929929
%%

apps/hellgate/src/hg_invoice_mutation.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ cart_is_not_valid_for_mutation(Lines) ->
6767
apply_mutations(Mutations, Invoice) ->
6868
lists:foldl(fun apply_mutation/2, Invoice, genlib:define(Mutations, [])).
6969

70-
apply_mutation(Mutation = {amount, #domain_InvoiceAmountMutation{mutated = NewAmount}}, Invoice) ->
70+
apply_mutation({amount, #domain_InvoiceAmountMutation{mutated = NewAmount}} = Mutation, Invoice) ->
7171
#domain_Invoice{cost = Cost, mutations = Mutations} = Invoice,
7272
update_invoice_details_price(NewAmount, Invoice#domain_Invoice{
7373
cost = Cost#domain_Cash{amount = NewAmount},
@@ -76,7 +76,7 @@ apply_mutation(Mutation = {amount, #domain_InvoiceAmountMutation{mutated = NewAm
7676
apply_mutation(_, Invoice) ->
7777
Invoice.
7878

79-
update_invoice_details_price(NewAmount, Invoice = #domain_Invoice{details = Details}) ->
79+
update_invoice_details_price(NewAmount, #domain_Invoice{details = Details} = Invoice) ->
8080
case Details#domain_InvoiceDetails.cart of
8181
Cart = #domain_InvoiceCart{lines = [Line]} ->
8282
NewCart = Cart#domain_InvoiceCart{
@@ -89,7 +89,7 @@ update_invoice_details_price(NewAmount, Invoice = #domain_Invoice{details = Deta
8989
Invoice
9090
end.
9191

92-
update_invoice_line_price(NewAmount, Line = #domain_InvoiceLine{price = Price}) ->
92+
update_invoice_line_price(NewAmount, #domain_InvoiceLine{price = Price} = Line) ->
9393
Line#domain_InvoiceLine{price = Price#domain_Cash{amount = NewAmount}}.
9494

9595
-spec make_mutations([mutation_params()], mutation_context()) -> [mutation()].

0 commit comments

Comments
 (0)