From 151f5d5d478f6e695dee74d2800540ab35ab6978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mil=C3=A1n=20B=C3=B3r?= Date: Sat, 14 Dec 2024 20:30:12 +0100 Subject: [PATCH] change(atom_naming_convention): do not apply to function names --- src/elvis_style.erl | 22 +++++++++++++++++-- .../examples/atom_naming_convention_utils.erl | 5 +++++ test/examples/pass_atom_naming_convention.erl | 3 ++- 3 files changed, 27 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 36f274ed..fe907706 100644 --- a/src/elvis_style.erl +++ b/src/elvis_style.erl @@ -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()]}. @@ -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 @@ -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 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().