Skip to content

Commit 7612541

Browse files
Act on non_reversible_form as an exception to atom naming conventions (#345)
* Act on `non_reversible_form` as an exception to atom naming conventions * Update atom_naming_convention -related test * Include specific execution conditions
1 parent 6923a83 commit 7612541

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

src/elvis_style.erl

+7-5
Original file line numberDiff line numberDiff line change
@@ -1413,13 +1413,15 @@ is_float_node(Node) ->
14131413
ktn_code:type(Node) =:= float.
14141414

14151415
%% @private
1416-
is_exception_class(error) ->
1416+
is_exception_or_non_reversible(error) ->
14171417
true;
1418-
is_exception_class(exit) ->
1418+
is_exception_or_non_reversible(exit) ->
14191419
true;
1420-
is_exception_class(throw) ->
1420+
is_exception_or_non_reversible(throw) ->
14211421
true;
1422-
is_exception_class(_) ->
1422+
is_exception_or_non_reversible(non_reversible_form) ->
1423+
true;
1424+
is_exception_or_non_reversible(_) ->
14231425
false.
14241426

14251427
%% @private
@@ -1429,7 +1431,7 @@ check_atom_names(Regex, RegexEnclosed, [AtomNode | RemainingAtomNodes], AccIn) -
14291431
AtomName0 = ktn_code:attr(text, AtomNode),
14301432
ValueAtomName = ktn_code:attr(value, AtomNode),
14311433
{IsEnclosed, AtomName} = string_strip_enclosed(AtomName0),
1432-
IsExceptionClass = is_exception_class(ValueAtomName),
1434+
IsExceptionClass = is_exception_or_non_reversible(ValueAtomName),
14331435
RE = re_compile_for_atom_type(IsEnclosed, Regex, RegexEnclosed),
14341436
AccOut =
14351437
case re:run(

test/examples/pass_maybe.erl

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
-module(pass_maybe).
2+
3+
-if(?OTP_RELEASE >= 25).
4+
5+
-feature(maybe_expr, enable).
6+
7+
-endif.
8+
9+
-export([sum_numbers/2]).
10+
11+
12+
-if(?OTP_RELEASE >= 25).
13+
sum_numbers(Number1, Number2) ->
14+
maybe
15+
ValidNumber1 ?= validate_number(Number1),
16+
ValidNumber2 ?= validate_number(Number2),
17+
ValidNumber1 + ValidNumber2
18+
else
19+
{error, invalid_number} ->
20+
{error, "One or both inputs are invalid numbers"}
21+
end.
22+
23+
validate_number(Number) when is_number(Number) ->
24+
Number;
25+
validate_number(_) ->
26+
{error, invalid_number}.
27+
-else.
28+
sum_numbers(Number1, Number2) ->
29+
Number1 + Number2.
30+
-endif.

test/style_SUITE.erl

+8
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,8 @@ verify_atom_naming_convention(Config) ->
12811281
PassPath = atom_to_list(PassModule) ++ "." ++ Ext,
12821282
PassModule2 = pass_atom_naming_convention_exception_class,
12831283
PassPath2 = atom_to_list(PassModule2) ++ "." ++ Ext,
1284+
PassModule3 = pass_maybe,
1285+
PassPath3 = atom_to_list(PassModule3) ++ "." ++ Ext,
12841286

12851287
[] =
12861288
elvis_core_apply_rule(Config,
@@ -1294,6 +1296,12 @@ verify_atom_naming_convention(Config) ->
12941296
atom_naming_convention,
12951297
#{regex => "^[^xwyhr]*$"},
12961298
PassPath2),
1299+
[] =
1300+
elvis_core_apply_rule(Config,
1301+
elvis_style,
1302+
atom_naming_convention,
1303+
#{regex => "^^[a-z]([a-zA-Z0-9@]*_?)*(_SUITE)?$"},
1304+
PassPath3),
12971305

12981306
% fail
12991307
FailModule = fail_atom_naming_convention,

0 commit comments

Comments
 (0)