From 70fd9d01fd076f4640da09fdfd53b310ec59a94c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Go=CC=81rny?= Date: Wed, 12 Oct 2016 14:56:40 +0200 Subject: [PATCH] Don't strip leading underscore, allow it by regex (explicit over implicity, you know) --- src/elvis_rulesets.erl | 2 +- src/elvis_style.erl | 9 +-------- test/style_SUITE.erl | 2 +- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/elvis_rulesets.erl b/src/elvis_rulesets.erl index dc139166..d59d745d 100644 --- a/src/elvis_rulesets.erl +++ b/src/elvis_rulesets.erl @@ -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) -> diff --git a/src/elvis_style.erl b/src/elvis_style.erl index 85032b0a..457dd557 100644 --- a/src/elvis_style.erl +++ b/src/elvis_style.erl @@ -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); diff --git a/test/style_SUITE.erl b/test/style_SUITE.erl index f1dbada7..9119e32f 100644 --- a/test/style_SUITE.erl +++ b/test/style_SUITE.erl @@ -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),