Skip to content

Commit

Permalink
qf-elvis: check files in subfolders of src/ (2600hz#2197)
Browse files Browse the repository at this point in the history
* qf-elvis: check files in subfolders of src/

* qf-elvis: remove trailing whitespace

* qf-elvis: remove all but 1 occurences of `if` expressions

* qf-elvis: remove last `if` expression along with dead code

* qf-elvis: also check HRLs

* qf-elvis: move elvis to Circle

* qf-elvis: move `make elvis` after `make` as it requires deps/ to exist
  • Loading branch information
fenollp authored and k-anderson committed Jul 6, 2016
1 parent 9a6f61f commit cf82177
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 107 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
92 changes: 10 additions & 82 deletions applications/callflow/src/module/cf_temporal_route.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand All @@ -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;
Expand Down Expand Up @@ -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});
Expand Down Expand Up @@ -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 ->
Expand All @@ -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 ).

%%--------------------------------------------------------------------
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion applications/callflow/src/module/cf_voicemail.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions applications/crossbar/src/modules/cb_resource_selectors.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <<CountryPrefix/binary, PrefixQuery/binary>>,
Prefix = <<CountryPrefix/binary, PrefixQuery/binary>>,
Quantity = kz_json:get_ne_value(<<"quantity">>, QueryString, 1),
lists:reverse(
lists:foldl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <<CountryPrefix/binary, PrefixQuery/binary>>,
Prefix = <<CountryPrefix/binary, PrefixQuery/binary>>,
Quantity = kz_json:get_value(<<"quantity">>, JObj),
OnSuccess =
fun(C) ->
Expand Down
1 change: 1 addition & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
- |
Expand Down
26 changes: 14 additions & 12 deletions core/kazoo_attachments/src/aws/kz_aws_s3.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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}) ->
Expand Down
12 changes: 6 additions & 6 deletions core/kazoo_services/src/bookkeepers/kz_bookkeeper_braintree.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down
6 changes: 5 additions & 1 deletion make/elvis.config
Original file line number Diff line number Diff line change
@@ -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}

Expand Down

0 comments on commit cf82177

Please sign in to comment.