Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change(atom_naming_convention): do not apply to function names #378

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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().