Skip to content

Commit

Permalink
Don't strip leading underscore, allow it by regex (explicit over impl…
Browse files Browse the repository at this point in the history
…icity, you know)
  • Loading branch information
bartekgorny committed Oct 12, 2016
1 parent 387f664 commit 70fd9d0
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/elvis_rulesets.erl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ rules(erl_files) ->
, {elvis_style, no_debug_call, #{ignore => [elvis, elvis_utils]}}
, { elvis_style
, variable_naming_convention
, #{regex => "^([A-Z][0-9a-zA-Z]*)$"}
, #{regex => "^_?([A-Z][0-9a-zA-Z]*)$"}
}
];
rules(makefiles) ->
Expand Down
9 changes: 1 addition & 8 deletions src/elvis_style.erl
Original file line number Diff line number Diff line change
Expand Up @@ -636,14 +636,7 @@ no_nested_try_catch(Config, Target, _RuleConfig) ->
%% Variables name
check_variables_name(_Regex, []) -> [];
check_variables_name(Regex, [Variable | RemainingVars]) ->
VariableName = atom_to_list(ktn_code:attr(name, Variable)),
%% Replace the leading underline (if any) in the variable name.
VariableNameStr = case length(VariableName) of
(N) when N > 1 ->
[_ | TempStr] = re:replace(VariableName, "^_?", ""),
binary_to_list(TempStr);
(_) -> VariableName
end,
VariableNameStr = atom_to_list(ktn_code:attr(name, Variable)),
case re:run(VariableNameStr, Regex) of
nomatch when VariableNameStr == "_" ->
check_variables_name(Regex, RemainingVars);
Expand Down
2 changes: 1 addition & 1 deletion test/style_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ verify_variable_naming_convention(_Config) ->
ElvisConfig = elvis_config:default(),
SrcDirs = elvis_config:dirs(ElvisConfig),

RuleConfig = #{regex => "^([A-Z][0-9a-zA-Z]*)$"},
RuleConfig = #{regex => "^_?([A-Z][0-9a-zA-Z]*)$"},

PathPass = "pass_variable_naming_convention.erl",
{ok, FilePass} = elvis_test_utils:find_file(SrcDirs, PathPass),
Expand Down

0 comments on commit 70fd9d0

Please sign in to comment.