Skip to content

Commit

Permalink
change(atom_naming_convention): do not apply to function names
Browse files Browse the repository at this point in the history
  • Loading branch information
bormilan committed Dec 14, 2024
1 parent e81a9d5 commit 151f5d5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
22 changes: 20 additions & 2 deletions src/elvis_style.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ atom_naming_convention(Config, Target, RuleConfig) ->
Regex = option(regex, RuleConfig, atom_naming_convention),
RegexEnclosed =
specific_or_default(option(enclosed_atoms, RuleConfig, atom_naming_convention), Regex),
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, RegexEnclosed, AtomNodes, []).

-type no_init_lists_config() :: #{behaviours => [atom()]}.
Expand Down Expand Up @@ -1710,7 +1710,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 @@ -2038,6 +2041,21 @@ 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),
case ktn_code:type(Parent) of
remote ->
true;
_ ->
false
end
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 151f5d5

Please sign in to comment.