diff --git a/.travis.yml b/.travis.yml index f568cc4b0d0..b89941a350e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,6 @@ before_install: script: - make compile-test - - make elvis - make eunit - # ERL_LIBS="$HOME/proper" ERLC_OPTS='-DPROPER' make compile-test - # ERL_LIBS="$HOME/proper" make eunit diff --git a/applications/callflow/src/module/cf_temporal_route.erl b/applications/callflow/src/module/cf_temporal_route.erl index 31031f5ac95..e817bb8804b 100644 --- a/applications/callflow/src/module/cf_temporal_route.erl +++ b/applications/callflow/src/module/cf_temporal_route.erl @@ -467,7 +467,7 @@ next_rule_date(#rule{cycle = <<"weekly">> } ,{Y1, M1, D1}=_PrevDate ) -> - DOW0 = day_of_the_week({Y1, M1, D1}), + DOW0 = calendar:day_of_the_week({Y1, M1, D1}), Distance = iso_week_difference({Y0, M0, D0}, {Y1, M1, D1}), Offset = trunc( Distance / I0 ) * I0, @@ -482,7 +482,7 @@ next_rule_date(#rule{cycle = <<"weekly">> %% Non Empty List that failed the guard: %% During an 'inactive' week _ -> - {WY0, W0} = iso_week_number({Y0, M0, D0}), + {WY0, W0} = calendar:iso_week_number({Y0, M0, D0}), {Y2, M2, D2} = iso_week_to_gregorian_date({WY0, W0 + Offset + I0}), normalize_date({Y2, M2, ( D2 - 1 ) + to_dow( hd( Weekdays ) )}) end; @@ -791,7 +791,7 @@ to_wday(7) -> <<"sunday">>. -spec find_next_weekday(kz_date(), wday()) -> kz_date(). find_next_weekday({Y, M, D}, Weekday) -> RefDOW = to_dow(Weekday), - case day_of_the_week({Y, M, D}) of + case calendar:day_of_the_week({Y, M, D}) of %% Today is the DOW we wanted, calculate for next week RefDOW -> normalize_date({Y, M, D + 7}); @@ -872,7 +872,7 @@ date_of_dow(Year, Month, Weekday, Ordinal) -> RefDays = calendar:date_to_gregorian_days(RefDate), DOW = to_dow(Weekday), Occurance = from_ordinal(Ordinal), - Days = case day_of_the_week(RefDate) of + Days = case calendar:day_of_the_week(RefDate) of DOW -> RefDays + 7 + (7 * Occurance ); RefDOW when DOW < RefDOW -> @@ -899,8 +899,8 @@ date_of_dow(Year, Month, Weekday, Ordinal) -> %%-------------------------------------------------------------------- -spec iso_week_difference(kz_date(), kz_date()) -> non_neg_integer(). iso_week_difference({Y0, M0, D0}, {Y1, M1, D1}) -> - DS0 = calendar:date_to_gregorian_days(iso_week_to_gregorian_date(iso_week_number({Y0, M0, D0}))), - DS1 = calendar:date_to_gregorian_days(iso_week_to_gregorian_date(iso_week_number({Y1, M1, D1}))), + DS0 = calendar:date_to_gregorian_days(iso_week_to_gregorian_date(calendar:iso_week_number({Y0, M0, D0}))), + DS1 = calendar:date_to_gregorian_days(iso_week_to_gregorian_date(calendar:iso_week_number({Y1, M1, D1}))), trunc( abs( DS0 - DS1 ) / 7 ). %%-------------------------------------------------------------------- @@ -912,87 +912,15 @@ iso_week_difference({Y0, M0, D0}, {Y1, M1, D1}) -> -spec iso_week_to_gregorian_date(kz_iso_week()) -> kz_date(). iso_week_to_gregorian_date({Year, Week}) -> Jan1 = calendar:date_to_gregorian_days(Year, 1, 1), - Offset = 4 - day_of_the_week(Year, 1, 4), + Offset = 4 - calendar:day_of_the_week(Year, 1, 4), Days = - if - Offset =:= 0 -> - Jan1 + ( Week * 7 ); - 'true' -> + case Offset =:= 0 of + 'true' -> Jan1 + ( Week * 7 ); + 'false' -> Jan1 + Offset + ( ( Week - 1 ) * 7 ) end, calendar:gregorian_days_to_date(Days). -%%-------------------------------------------------------------------- -%% @private -%% @doc -%% Wrapper for calender:iso_week_number introduced in R14B02 (?) using -%% a local copy on older systems -%% @end -%%-------------------------------------------------------------------- --spec iso_week_number(kz_date()) -> kz_iso_week(). -iso_week_number(Date) -> - case erlang:function_exported('calendar', 'iso_week_number', 1) of - 'true' -> calendar:iso_week_number(Date); - 'false' -> our_iso_week_number(Date) - end. - --spec day_of_the_week(kz_date()) -> kz_day(). -day_of_the_week({Year, Month, Day}=Date) -> - case erlang:function_exported('calendar', 'day_of_the_week', 1) of - 'true' -> calendar:day_of_the_week(Date); - 'false' -> our_day_of_the_week(Year, Month, Day) - end. - --spec day_of_the_week(kz_year(), kz_month(), kz_day()) -> kz_day(). -day_of_the_week(Year, Month, Day) -> - case erlang:function_exported('calendar', 'day_of_the_week', 3) of - 'true' -> calendar:day_of_the_week(Year, Month, Day); - 'false' -> our_day_of_the_week(Year, Month, Day) - end. - -%% TAKEN FROM THE R14B02 SOURCE FOR calender.erl -our_iso_week_number({Year,_Month,_Day}=Date) -> - D = calendar:date_to_gregorian_days(Date), - W01_1_Year = gregorian_days_of_iso_w01_1(Year), - W01_1_NextYear = gregorian_days_of_iso_w01_1(Year + 1), - if - W01_1_Year =< D - andalso D < W01_1_NextYear -> - %% Current Year Week 01..52(,53) - {Year, (D - W01_1_Year) div 7 + 1}; - D < W01_1_Year -> - %% Previous Year 52 or 53 - PWN = case day_of_the_week(Year - 1, 1, 1) of - 4 -> 53; - _ -> case day_of_the_week(Year - 1, 12, 31) of - 4 -> 53; - _ -> 52 - end - end, - {Year - 1, PWN}; - W01_1_NextYear =< D -> - %% Next Year, Week 01 - {Year + 1, 1} - end. - --spec gregorian_days_of_iso_w01_1(calendar:year()) -> non_neg_integer(). -gregorian_days_of_iso_w01_1(Year) -> - D0101 = calendar:date_to_gregorian_days(Year, 1, 1), - DOW = calendar:day_of_the_week(Year, 1, 1), - if DOW =< 4 -> - D0101 - DOW + 1; - 'true' -> - D0101 + 7 - DOW + 1 - end. - -%% day_of_the_week(Year, Month, Day) -%% day_of_the_week({Year, Month, Day}) -%% -%% Returns: 1 | .. | 7. Monday = 1, Tuesday = 2, ..., Sunday = 7. --spec our_day_of_the_week(calendar:year(), calendar:month(), calendar:day()) -> calendar:daynum(). -our_day_of_the_week(Year, Month, Day) -> - (calendar:date_to_gregorian_days(Year, Month, Day) + 5) rem 7 + 1. - -spec find_active_days(ne_binaries(), kz_day()) -> [kz_daynum()]. find_active_days(Weekdays, DOW0) -> [DOW1 diff --git a/applications/callflow/src/module/cf_voicemail.erl b/applications/callflow/src/module/cf_voicemail.erl index 93f97e952bf..8488a040492 100644 --- a/applications/callflow/src/module/cf_voicemail.erl +++ b/applications/callflow/src/module/cf_voicemail.erl @@ -1166,7 +1166,8 @@ change_pin(#mailbox{mailbox_id=Id {'ok', Pin} = confirm_new_pin(Interdigit, Call), lager:info("collected second pin"), - if Pin =:= <<>> -> throw('pin_empty'); 'true' -> 'ok' end, + Pin =:= <<>> + andalso throw('pin_empty'), lager:info("entered pin is not empty"), AccountDb = kapps_call:account_db(Call), diff --git a/applications/crossbar/src/modules/cb_resource_selectors.erl b/applications/crossbar/src/modules/cb_resource_selectors.erl index f08359b024c..ad0e3e543cd 100644 --- a/applications/crossbar/src/modules/cb_resource_selectors.erl +++ b/applications/crossbar/src/modules/cb_resource_selectors.erl @@ -380,7 +380,7 @@ do_delete_all_selectors(Db, Options, AccStats) -> Stats = case [ kz_json:get_ne_value(<<"id">>, R, []) || R <- SearchResult ] of [] -> AccStats; [[]] -> AccStats; - IDs -> + IDs -> NewStats = do_delete_selectors(Db, IDs, AccStats), do_delete_all_selectors(Db, Options, NewStats) end, @@ -446,7 +446,7 @@ maybe_send_db_change_notice(Db, Stats) -> case props:get_integer_value('success', Stats, 0) > 0 andalso ?SUPPRESS_SRS_NOTICE of - 'true' -> + 'true' -> _ = kz_util:spawn(fun() -> kzs_publish:publish_db(Db, 'edited') end), 'ok'; 'false' -> 'ok' diff --git a/applications/crossbar/src/modules_v1/cb_phone_numbers_v1.erl b/applications/crossbar/src/modules_v1/cb_phone_numbers_v1.erl index e9efa71aa88..ca87159ef89 100644 --- a/applications/crossbar/src/modules_v1/cb_phone_numbers_v1.erl +++ b/applications/crossbar/src/modules_v1/cb_phone_numbers_v1.erl @@ -419,7 +419,7 @@ get_numbers(QueryString) -> PrefixQuery = kz_json:get_ne_value(?PREFIX, QueryString), Country = kz_json:get_ne_value(?COUNTRY, QueryString, ?DEFAULT_COUNTRY), CountryPrefix = knm_util:prefix_for_country(Country), - Prefix = <>, + Prefix = <>, Quantity = kz_json:get_ne_value(<<"quantity">>, QueryString, 1), lists:reverse( lists:foldl( diff --git a/applications/crossbar/src/modules_v2/cb_phone_numbers_v2.erl b/applications/crossbar/src/modules_v2/cb_phone_numbers_v2.erl index 309c9401def..b2b5478756b 100644 --- a/applications/crossbar/src/modules_v2/cb_phone_numbers_v2.erl +++ b/applications/crossbar/src/modules_v2/cb_phone_numbers_v2.erl @@ -493,7 +493,7 @@ find_numbers(Context) -> PrefixQuery = kz_json:get_ne_value(?PREFIX, JObj), Country = kz_json:get_ne_value(?COUNTRY, JObj, ?DEFAULT_COUNTRY), CountryPrefix = knm_util:prefix_for_country(Country), - Prefix = <>, + Prefix = <>, Quantity = kz_json:get_value(<<"quantity">>, JObj), OnSuccess = fun(C) -> diff --git a/circle.yml b/circle.yml index b0924c4985e..31171ea184a 100644 --- a/circle.yml +++ b/circle.yml @@ -39,6 +39,7 @@ test: git diff exit 1 fi + - . ~/.kerl/$OTP_VERSION/activate && make elvis - . ~/.kerl/$OTP_VERSION/activate && make xref - . ~/.kerl/$OTP_VERSION/activate && make sup_completion - | diff --git a/core/kazoo_attachments/src/aws/kz_aws_s3.erl b/core/kazoo_attachments/src/aws/kz_aws_s3.erl index 53c319fcb95..38b880146b4 100644 --- a/core/kazoo_attachments/src/aws/kz_aws_s3.erl +++ b/core/kazoo_attachments/src/aws/kz_aws_s3.erl @@ -1205,13 +1205,7 @@ s3_request2_no_update(Config, Method, Host, Path, Subresource, Params, Body, Hea ,HostURI ,EscapedPath ,case Subresource of "" -> ""; _ -> [$?, Subresource] end - ,if - Params =:= [] -> ""; - Subresource =:= "" -> - [$?, kz_aws_http:make_query_string(Params, 'no_assignment')]; - 'true' -> - [$&, kz_aws_http:make_query_string(Params, 'no_assignment')] - end + ,query_string_from_params(Params, Subresource) ]), Request = #aws_request{service = 's3' @@ -1241,6 +1235,12 @@ s3_request2_no_update(Config, Method, Host, Path, Subresource, Params, Body, Hea Request3 = kz_aws_retry:request(Config, Request2, fun s3_result_fun/1), kz_aws:request_to_return(Request3). +query_string_from_params([], _SubResource) -> ""; +query_string_from_params(Params, "") -> + [$?, kz_aws_http:make_query_string(Params, 'no_assignment')]; +query_string_from_params(Params, _SubResource) -> + [$&, kz_aws_http:make_query_string(Params, 'no_assignment')]. + s3_result_fun(#aws_request{response_type = 'ok'} = Request) -> Request; s3_result_fun(#aws_request{response_type = 'error' @@ -1276,15 +1276,17 @@ make_authorization(Config, Method, ContentMD5, ContentType, Date, AmzHeaders, ,case Host of "" -> ""; _ -> [$/, Host] end ,Resource ,case Subresource of "" -> ""; _ -> [$?, Subresource] end - ,if - ParamsQueryString =:= "" -> ""; - Subresource =:= "" -> [$?, ParamsQueryString]; - 'true' -> [$&, ParamsQueryString] - end + ,string_from_params_QS(ParamsQueryString, Subresource) ], Signature = base64:encode(kz_att_util:sha_mac(Config#aws_config.secret_access_key, StringToSign)), ["AWS ", Config#aws_config.access_key_id, $:, Signature]. +string_from_params_QS("", _SubResource) -> ""; +string_from_params_QS(ParamsQueryString, "") -> + [$?, ParamsQueryString]; +string_from_params_QS(ParamsQueryString, _SubResource) -> + [$&, ParamsQueryString]. + default_config() -> kz_aws:default_config(). port_spec(#aws_config{s3_port=80}) -> diff --git a/core/kazoo_services/src/bookkeepers/kz_bookkeeper_braintree.erl b/core/kazoo_services/src/bookkeepers/kz_bookkeeper_braintree.erl index 66d08a72a82..76cb6f216e3 100644 --- a/core/kazoo_services/src/bookkeepers/kz_bookkeeper_braintree.erl +++ b/core/kazoo_services/src/bookkeepers/kz_bookkeeper_braintree.erl @@ -358,16 +358,16 @@ set_reason(BTTransaction, Transaction, 'undefined') -> IsApi = kz_json:is_true(<<"is_api">>, BTTransaction), IsRecurring = kz_json:is_true(<<"is_recurring">>, BTTransaction), IsProrated = transaction_is_prorated(BTTransaction), - if - IsProrated, IsRecurring -> + case {IsProrated, IsRecurring, IsApi} of + {'true', 'true', _} -> kz_transaction:set_reason(<<"recurring_prorate">>, Transaction); - IsApi, IsRecurring -> + {_, 'true', 'true'} -> kz_transaction:set_reason(<<"recurring_prorate">>, Transaction); - IsRecurring -> + {_, 'true', _} -> kz_transaction:set_reason(<<"monthly_recurring">>, Transaction); - IsApi -> + {_, _, 'true'} -> kz_transaction:set_reason(<<"manual_addition">>, Transaction); - 'true' -> + _ -> kz_transaction:set_reason(<<"unknown">>, Transaction) end; set_reason(_BTTransaction, Transaction, Code) -> diff --git a/make/elvis.config b/make/elvis.config index 446b1cf6141..0687433aabf 100644 --- a/make/elvis.config +++ b/make/elvis.config @@ -1,10 +1,14 @@ [{elvis, [ {config, [#{dirs => [ "applications/*/src" + , "applications/*/src/*" , "core/*/src" + , "core/*/src/*" + , "applications/include" + , "core/include" , "applications/*/test" , "core/*/test" ], - filter => "*.erl", + filter => "*.[eh]rl", rules => [ {elvis_style, no_trailing_whitespace, #{ignore_empty_lines => false}} %% , {elvis_style, no_tabs}