Skip to content

Commit

Permalink
Don't use non-built in macros in new code
Browse files Browse the repository at this point in the history
  • Loading branch information
paulo-ferraz-oliveira committed Sep 18, 2020
1 parent 317c0d5 commit 59300dd
Showing 1 changed file with 38 additions and 38 deletions.
76 changes: 38 additions & 38 deletions src/elvis_style.erl
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ default(atom_naming_convention) ->
function_naming_convention_config()) ->
[elvis_result:item()].
function_naming_convention(Config, Target, RuleConfig) ->
Regex = option(regex, RuleConfig, ?FUNCTION_NAME),
Ignores = option(ignore, RuleConfig, ?FUNCTION_NAME),
Regex = option(regex, RuleConfig, function_naming_convention),
Ignores = option(ignore, RuleConfig, function_naming_convention),
{Root, _} = elvis_file:parse_tree(Config, Target),
ModuleName = elvis_code:module_name(Root),
IgnoredFuns = lists:filtermap(
Expand Down Expand Up @@ -325,8 +325,8 @@ errors_for_function_names(Regex, [FunctionName | RemainingFuncNames]) ->
variable_naming_convention_config()) ->
[elvis_result:item()].
variable_naming_convention(Config, Target, RuleConfig) ->
IgnoreModules = option(ignore, RuleConfig, ?FUNCTION_NAME),
Regex = option(regex, RuleConfig, ?FUNCTION_NAME),
IgnoreModules = option(ignore, RuleConfig, variable_naming_convention),
Regex = option(regex, RuleConfig, variable_naming_convention),
{Root, _} = elvis_file:parse_tree(Config, Target),
ModuleName = elvis_code:module_name(Root),
case lists:member(ModuleName, IgnoreModules) of
Expand All @@ -349,8 +349,8 @@ variable_naming_convention(Config, Target, RuleConfig) ->
line_length_config()) ->
[elvis_result:item()].
line_length(_Config, Target, RuleConfig) ->
Limit = option(limit, RuleConfig, ?FUNCTION_NAME),
SkipComments = option(skip_comments, RuleConfig, ?FUNCTION_NAME),
Limit = option(limit, RuleConfig, line_length),
SkipComments = option(skip_comments, RuleConfig, line_length),
{Src, #{encoding := Encoding}} = elvis_file:src(Target),
Args = [Limit, SkipComments, Encoding],
elvis_utils:check_lines(Src, fun check_line_length/3, Args).
Expand All @@ -377,7 +377,7 @@ no_spaces(_Config, Target, _RuleConfig) ->
[elvis_result:item()].
no_trailing_whitespace(_Config, Target, RuleConfig) ->
{Src, _} = elvis_file:src(Target),
IgnoreEmptyLines = option(ignore_empty_lines, RuleConfig, ?FUNCTION_NAME),
IgnoreEmptyLines = option(ignore_empty_lines, RuleConfig, no_trailing_whitespace),
elvis_utils:check_lines(Src,
fun(Src1, Fun, _Args) ->
check_no_trailing_whitespace(Src1, Fun, IgnoreEmptyLines)
Expand All @@ -393,12 +393,12 @@ no_trailing_whitespace(_Config, Target, RuleConfig) ->
macro_names_config()) ->
[elvis_result:item()].
macro_names(Config, Target, RuleConfig) ->
IgnoreModules = option(ignore, RuleConfig, ?FUNCTION_NAME),
IgnoreModules = option(ignore, RuleConfig, macro_names),
{Root, _File} = elvis_file:parse_tree(Config, Target),
ModuleName = elvis_code:module_name(Root),
case lists:member(ModuleName, IgnoreModules) of
false ->
Regexp = option(regex, RuleConfig, ?FUNCTION_NAME),
Regexp = option(regex, RuleConfig, macro_names),
MacroNodes = elvis_code:find(fun is_macro_define_node/1, Root,
#{traverse => all, mode => node}),
check_macro_names(Regexp, MacroNodes, _ResultsIn = []);
Expand All @@ -423,7 +423,7 @@ macro_module_names(Config, Target, _RuleConfig) ->
operator_spaces_config()) ->
[elvis_result:item()].
operator_spaces(Config, Target, RuleConfig) ->
Rules = option(rules, RuleConfig, ?FUNCTION_NAME),
Rules = option(rules, RuleConfig, operator_spaces),
{Src, #{encoding := Encoding}} = elvis_file:src(Target),
{Root, _} = elvis_file:parse_tree(Config, Target),

Expand Down Expand Up @@ -460,8 +460,8 @@ is_punctuation_token(Node) ->
nesting_level_config()) ->
[elvis_result:item()].
nesting_level(Config, Target, RuleConfig) ->
Level = option(level, RuleConfig, ?FUNCTION_NAME),
IgnoreModules = option(ignore, RuleConfig, ?FUNCTION_NAME),
Level = option(level, RuleConfig, nesting_level),
IgnoreModules = option(ignore, RuleConfig, nesting_level),

{Root, _} = elvis_file:parse_tree(Config, Target),
ModuleName = elvis_code:module_name(Root),
Expand All @@ -481,8 +481,8 @@ nesting_level(Config, Target, RuleConfig) ->
god_modules_config()) ->
[elvis_result:item()].
god_modules(Config, Target, RuleConfig) ->
Limit = option(limit, RuleConfig, ?FUNCTION_NAME),
IgnoreModules = option(ignore, RuleConfig, ?FUNCTION_NAME),
Limit = option(limit, RuleConfig, god_modules),
IgnoreModules = option(ignore, RuleConfig, god_modules),

{Root, _} = elvis_file:parse_tree(Config, Target),
ModuleName = elvis_code:module_name(Root),
Expand Down Expand Up @@ -524,7 +524,7 @@ no_if_expression(Config, Target, _RuleConfig) ->
invalid_dynamic_call_config()) ->
[elvis_result:item()].
invalid_dynamic_call(Config, Target, RuleConfig) ->
IgnoreModules = option(ignore, RuleConfig, ?FUNCTION_NAME),
IgnoreModules = option(ignore, RuleConfig, invalid_dynamic_call),
{Root, _} = elvis_file:parse_tree(Config, Target),
ModuleName = elvis_code:module_name(Root),

Expand All @@ -547,7 +547,7 @@ invalid_dynamic_call(Config, Target, RuleConfig) ->
used_ignored_variable_config()) ->
[elvis_result:item()].
used_ignored_variable(Config, Target, RuleConfig) ->
IgnoreModules = option(ignore, RuleConfig, ?FUNCTION_NAME),
IgnoreModules = option(ignore, RuleConfig, used_ignored_variable),
{Root, _} = elvis_file:parse_tree(Config, Target),
ResultFun = result_node_line_col_fun(?USED_IGNORED_VAR_MSG),
ModuleName = elvis_code:module_name(Root),
Expand Down Expand Up @@ -601,8 +601,8 @@ no_behavior_info(Config, Target, _RuleConfig) ->
module_naming_convention_config()) ->
[elvis_result:item()].
module_naming_convention(Config, Target, RuleConfig) ->
Regex = option(regex, RuleConfig, ?FUNCTION_NAME),
IgnoreModules = option(ignore, RuleConfig, ?FUNCTION_NAME),
Regex = option(regex, RuleConfig, module_naming_convention),
IgnoreModules = option(ignore, RuleConfig, module_naming_convention),

{Root, _} = elvis_file:parse_tree(Config, Target),
ModuleName = elvis_code:module_name(Root),
Expand Down Expand Up @@ -666,8 +666,8 @@ no_spec_with_records(Config, Target, _RuleConfig) ->
dont_repeat_yourself_config()) ->
[elvis_result:item()].
dont_repeat_yourself(Config, Target, RuleConfig) ->
MinComplexity = option(min_complexity, RuleConfig, ?FUNCTION_NAME),
IgnoreModules = option(ignore, RuleConfig, ?FUNCTION_NAME),
MinComplexity = option(min_complexity, RuleConfig, dont_repeat_yourself),
IgnoreModules = option(ignore, RuleConfig, dont_repeat_yourself),

{Root, _} = elvis_file:parse_tree(Config, Target),
ModuleName = elvis_code:module_name(Root),
Expand Down Expand Up @@ -701,10 +701,10 @@ dont_repeat_yourself(Config, Target, RuleConfig) ->
max_module_length_config()) ->
[elvis_result:item()].
max_module_length(Config, Target, RuleConfig) ->
MaxLength = option(max_length, RuleConfig, ?FUNCTION_NAME),
IgnoreModules = option(ignore, RuleConfig, ?FUNCTION_NAME),
CountComments = option(count_comments, RuleConfig, ?FUNCTION_NAME),
CountWhitespace = option(count_whitespace, RuleConfig, ?FUNCTION_NAME),
MaxLength = option(max_length, RuleConfig, max_module_length),
IgnoreModules = option(ignore, RuleConfig, max_module_length),
CountComments = option(count_comments, RuleConfig, max_module_length),
CountWhitespace = option(count_whitespace, RuleConfig, max_module_length),

{Root, _} = elvis_file:parse_tree(Config, Target),
{Src, _} = elvis_file:src(Target),
Expand Down Expand Up @@ -739,10 +739,10 @@ max_module_length(Config, Target, RuleConfig) ->
max_function_length_config()) ->
[elvis_result:item()].
max_function_length(Config, Target, RuleConfig) ->
IgnoreFunctions = option(ignore_functions, RuleConfig, ?FUNCTION_NAME),
MaxLength = option(max_length, RuleConfig, ?FUNCTION_NAME),
CountComments = option(count_comments, RuleConfig, ?FUNCTION_NAME),
CountWhitespace = option(count_whitespace, RuleConfig, ?FUNCTION_NAME),
IgnoreFunctions = option(ignore_functions, RuleConfig, max_function_length),
MaxLength = option(max_length, RuleConfig, max_function_length),
CountComments = option(count_comments, RuleConfig, max_function_length),
CountWhitespace = option(count_whitespace, RuleConfig, max_function_length),

{Root, _} = elvis_file:parse_tree(Config, Target),
{Src, _} = elvis_file:src(Target),
Expand Down Expand Up @@ -801,8 +801,8 @@ max_function_length(Config, Target, RuleConfig) ->
no_call_config()) ->
[elvis_result:item()].
no_call(Config, Target, RuleConfig) ->
DefaultFns = option(no_call_functions, RuleConfig, ?FUNCTION_NAME),
IgnoreModules = option(ignore, RuleConfig, ?FUNCTION_NAME),
DefaultFns = option(no_call_functions, RuleConfig, no_call),
IgnoreModules = option(ignore, RuleConfig, no_call),
no_call_common(Config, Target, IgnoreModules, DefaultFns, ?NO_CALL_MSG).


Expand All @@ -814,8 +814,8 @@ no_call(Config, Target, RuleConfig) ->
no_debug_call_config()) ->
[elvis_result:item()].
no_debug_call(Config, Target, RuleConfig) ->
DefaultFns = option(debug_functions, RuleConfig, ?FUNCTION_NAME),
IgnoreModules = option(ignore, RuleConfig, ?FUNCTION_NAME),
DefaultFns = option(debug_functions, RuleConfig, no_debug_call),
IgnoreModules = option(ignore, RuleConfig, no_debug_call),
no_call_common(Config, Target, IgnoreModules, DefaultFns, ?NO_DEBUG_CALL_MSG).


Expand All @@ -828,8 +828,8 @@ no_debug_call(Config, Target, RuleConfig) ->
[elvis_result:item()].

no_common_caveats_call(Config, Target, RuleConfig) ->
DefaultFns = option(caveat_functions, RuleConfig, ?FUNCTION_NAME),
IgnoreModules = option(ignore, RuleConfig, ?FUNCTION_NAME),
DefaultFns = option(caveat_functions, RuleConfig, no_common_caveats_call),
IgnoreModules = option(ignore, RuleConfig, no_common_caveats_call),
no_call_common(Config, Target, IgnoreModules, DefaultFns, ?NO_COMMON_CAVEATS_CALL_MSG).

-spec node_line_limits(ktn_code:tree_node())->
Expand Down Expand Up @@ -857,7 +857,7 @@ node_line_limits(FunctionNode) ->
[elvis_result:item()].
no_nested_try_catch(Config, Target, RuleConfig) ->
{Root, _} = elvis_file:parse_tree(Config, Target),
IgnoreModules = option(ignore, RuleConfig, ?FUNCTION_NAME),
IgnoreModules = option(ignore, RuleConfig, no_nested_try_catch),
case lists:member(elvis_code:module_name(Root), IgnoreModules) of
false -> Predicate = fun(Node) -> ktn_code:type(Node) == 'try' end,
ResultFun = result_node_line_fun(?NO_NESTED_TRY_CATCH),
Expand All @@ -882,12 +882,12 @@ no_nested_try_catch(Config, Target, RuleConfig) ->
atom_naming_convention(Config, Target, RuleConfig) ->
{Root, _File} = elvis_file:parse_tree(Config, Target),
ModuleName = elvis_code:module_name(Root),
IgnoreModules = option(ignore, RuleConfig, ?FUNCTION_NAME),
IgnoreModules = option(ignore, RuleConfig, atom_naming_convention),
case lists:member(ModuleName, IgnoreModules) of
false ->
Regex = option(regex, RuleConfig, ?FUNCTION_NAME),
Regex = option(regex, RuleConfig, atom_naming_convention),
RegexEnclosed
= enclosed_atoms_regex_or_same(option(enclosed_atoms, RuleConfig, ?FUNCTION_NAME), Regex),
= enclosed_atoms_regex_or_same(option(enclosed_atoms, RuleConfig, atom_naming_convention), Regex),
AtomNodes = elvis_code:find(fun is_atom_node/1, Root, #{traverse => all, mode => node}),
check_atom_names(Regex, RegexEnclosed, AtomNodes, []);
true ->
Expand Down

0 comments on commit 59300dd

Please sign in to comment.