From 1ddf014666259f16b5f235bfec7c311ecfc63252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=B3r=20Mil=C3=A1n?= <71042542+bormilan@users.noreply.github.com> Date: Mon, 16 Dec 2024 08:52:58 +0100 Subject: [PATCH] change(atom_naming_convention): do not apply to function names (#378) * change(atom_naming_convention): do not apply to function names * Update src/elvis_style.erl --------- Co-authored-by: Brujo Benavides --- src/elvis_style.erl | 17 +++++++++++++++-- test/examples/atom_naming_convention_utils.erl | 5 +++++ test/examples/pass_atom_naming_convention.erl | 3 ++- 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 test/examples/atom_naming_convention_utils.erl diff --git a/src/elvis_style.erl b/src/elvis_style.erl index 312f8d4c..fc41a931 100644 --- a/src/elvis_style.erl +++ b/src/elvis_style.erl @@ -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, @@ -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 @@ -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 diff --git a/test/examples/atom_naming_convention_utils.erl b/test/examples/atom_naming_convention_utils.erl new file mode 100644 index 00000000..28889586 --- /dev/null +++ b/test/examples/atom_naming_convention_utils.erl @@ -0,0 +1,5 @@ +-module(atom_naming_convention_utils). + +-export([thisIsIgnored/0]). + +thisIsIgnored() -> ok. diff --git a/test/examples/pass_atom_naming_convention.erl b/test/examples/pass_atom_naming_convention.erl index 9536ef86..90e14dd2 100644 --- a/test/examples/pass_atom_naming_convention.erl +++ b/test/examples/pass_atom_naming_convention.erl @@ -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().