Skip to content

Commit

Permalink
Fix 210: changes from QA feedback, fix CT test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacky Hui committed Oct 4, 2021
1 parent 444c9a4 commit 5ea5ba0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
30 changes: 15 additions & 15 deletions src/elvis_style.erl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
no_nested_try_catch/3,
atom_naming_convention/3,
numeric_format/3,
incorrect_behaviour_spelling/3,
behaviour_spelling/3,
option/3
]).

Expand Down Expand Up @@ -127,9 +127,9 @@
"Number ~p on line ~p does not respect the format "
"defined by the regular expression '~p'.").

-define(INCORRECT_BEHAVIOUR_SPELLING(SpellingType),
-define(BEHAVIOUR_SPELLING(SpellingType),
"The behavior/behaviour in line ~p is misspelt, please use the "
++ SpellingType ++ " spelling.").
++ atom_to_list(SpellingType) ++ " spelling.").

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Default values
Expand Down Expand Up @@ -238,12 +238,12 @@ default(numeric_format) ->
#{ regex => ".*"
, int_regex => same
, float_regex => same
}.

default(incorrect_behaviour_spelling) ->
#{ spelling_type => american
};

default(behaviour_spelling) ->
#{ spelling_type => behavior
}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Rules
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down Expand Up @@ -774,27 +774,27 @@ numeric_format(Config, Target, RuleConfig) ->
IntNodes,
check_numeric_format(FloatRegex, FloatNodes, [])).

-spec incorrect_behaviour_spelling(elvis_config:config(),
-spec behaviour_spelling(elvis_config:config(),
elvis_file:file(),
empty_rule_config()) ->
[elvis_result:item()].
incorrect_behaviour_spelling(Config, Target, RuleConfig) ->
SpellingType = option(spelling_type, RuleConfig, incorrect_behaviour_spelling),
behaviour_spelling(Config, Target, RuleConfig) ->
SpellingType = option(spelling_type, RuleConfig, behaviour_spelling),
Root = get_root(Config, Target, RuleConfig),
Predicate =
fun(Node) ->
NodeType = ktn_code:type(Node)
NodeType = ktn_code:type(Node),
case {NodeType, SpellingType} of
{behavior, british} -> true;
{behaviour, american} -> true;
{behavior, behaviour} -> true;
{behaviour, behavior} -> true;
_ -> false
end
end,
case elvis_code:find(Predicate, Root) of
[] -> [];
InconsistentBehaviorNodes ->
ResultFun = result_node_line_fun(?INCORRECT_BEHAVIOuR_SPELLING(SpellingType)),
lists:map(ResultFun, SpecNodes)
ResultFun = result_node_line_fun(?BEHAVIOUR_SPELLING(SpellingType)),
lists:map(ResultFun, InconsistentBehaviorNodes)
end.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down
2 changes: 1 addition & 1 deletion test/examples/american_behavior_spelling.erl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-module(british_behavior_spelling).
-module(american_behavior_spelling).

-dialyzer(no_behaviours).

Expand Down
13 changes: 7 additions & 6 deletions test/style_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
verify_elvis_attr_state_record_and_type/1,
verify_elvis_attr_used_ignored_variable/1,
verify_elvis_attr_variable_naming_convention/1,
verify_behaviour_spelling/1,
%% Non-rule
results_are_ordered_by_line/1,
oddities/1
Expand Down Expand Up @@ -550,19 +551,19 @@ verify_state_record_and_type(Config) ->
PathPassGenStateMState = "fail_state_record_and_type_gen_statem_state." ++ Ext,
[_] = elvis_core_apply_rule(Config, elvis_style, state_record_and_type, #{}, PathPassGenStateMState).

-spec verify_incorrect_behaviour_spelling(config()) -> any().
verify_incorrect_behaviour_spelling(Config) ->
-spec verify_behaviour_spelling(config()) -> any().
verify_behaviour_spelling(Config) ->
Ext = proplists:get_value(test_file_ext, Config, "erl"),

PathFail = "british_behaviour_spelling." ++ Ext,
[_, _, _] = elvis_core_apply_rule(Config, elvis_style, incorrect_behaviour_spelling, #{spelling_type => american}, PathFail),
[_] = elvis_core_apply_rule(Config, elvis_style, behaviour_spelling, #{spelling_type => behavior}, PathFail),
PathFail1 = "american_behavior_spelling." ++ Ext,
[_, _, _] = elvis_core_apply_rule(Config, elvis_style, incorrect_behaviour_spelling, #{spelling_type => british}, PathFail1),
[_] = elvis_core_apply_rule(Config, elvis_style, behaviour_spelling, #{spelling_type => behaviour}, PathFail1),

PathPass = "british_behaviour_spelling." ++ Ext,
[] = elvis_core_apply_rule(Config, elvis_style, incorrect_behaviour_spelling, #{spelling_type => british}, PathPass),
[] = elvis_core_apply_rule(Config, elvis_style, behaviour_spelling, #{spelling_type => behaviour}, PathPass),
PathPass1 = "american_behavior_spelling." ++ Ext,
[] = elvis_core_apply_rule(Config, elvis_style, incorrect_behaviour_spelling, #{spelling_type => american}, PathPass1).
[] = elvis_core_apply_rule(Config, elvis_style, behaviour_spelling, #{spelling_type => behavior}, PathPass1).

-spec verify_no_spec_with_records(config()) -> any().
verify_no_spec_with_records(Config) ->
Expand Down

0 comments on commit 5ea5ba0

Please sign in to comment.