Skip to content

Commit

Permalink
change(atom_naming_convention): do not apply to function names (#378)
Browse files Browse the repository at this point in the history
* change(atom_naming_convention): do not apply to function names

* Update src/elvis_style.erl

---------

Co-authored-by: Brujo Benavides <[email protected]>
  • Loading branch information
bormilan and elbrujohalcon authored Dec 16, 2024
1 parent ecc035a commit 1ddf014
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/elvis_style.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ atom_naming_convention(Config, Target, RuleConfig) ->
ForbiddenEnclosedRegex =
specific_or_default(option(forbidden_enclosed_regex, RuleConfig, atom_naming_convention),
ForbiddenRegex),
AtomNodes = elvis_code:find(fun is_atom_node/1, Root, #{traverse => all, mode => node}),
AtomNodes = elvis_code:find(fun is_atom_node/1, Root, #{traverse => all, mode => zipper}),
check_atom_names(Regex,
ForbiddenRegex,
RegexEnclosed,
Expand Down Expand Up @@ -1800,7 +1800,10 @@ re_compile_for_atom_type(true = _IsEnclosed, _Regex, RegexEnclosed) ->

%% @private
is_atom_node(MaybeAtom) ->
ktn_code:type(MaybeAtom) =:= atom.
ktn_code:type(
zipper:node(MaybeAtom))
=:= atom
andalso not check_parent_remote(MaybeAtom).

%% Variables name
%% @private
Expand Down Expand Up @@ -2141,6 +2144,16 @@ check_parent_match_or_macro(Zipper) ->
end
end.

%% @private
check_parent_remote(Zipper) ->
case zipper:up(Zipper) of
undefined ->
false;
ParentZipper ->
Parent = zipper:node(ParentZipper),
remote == ktn_code:type(Parent)
end.

%% State record in OTP module

%% @private
Expand Down
5 changes: 5 additions & 0 deletions test/examples/atom_naming_convention_utils.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-module(atom_naming_convention_utils).

-export([thisIsIgnored/0]).

thisIsIgnored() -> ok.
3 changes: 2 additions & 1 deletion test/examples/pass_atom_naming_convention.erl
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ for_test() ->
non200, % valid, even without underscores
valid_200even_if_numb3rs_appear_between_letters,
blahblah_SUITE,
x.
x,
atom_naming_convention_utils:thisIsIgnored().

0 comments on commit 1ddf014

Please sign in to comment.