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

Breaking: update atom naming convention's default regex #356

Merged
merged 4 commits into from
Sep 16, 2024
Merged
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
2 changes: 1 addition & 1 deletion src/elvis_style.erl
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ default(no_common_caveats_call) ->
{timer, send_interval, 3},
{erlang, size, 1}]};
default(atom_naming_convention) ->
#{regex => "^([a-z][a-z0-9]*_?)*(_SUITE)?$", enclosed_atoms => ".*"};
#{regex => "^[a-z](_?[a-z0-9]+)*(_SUITE)?$", enclosed_atoms => ".*"};
%% Not restrictive. Those who want more restrictions can set it like "^[^_]*$"
default(numeric_format) ->
#{regex => ".*",
Expand Down
10 changes: 9 additions & 1 deletion test/examples/fail_atom_naming_convention.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@ for_test() ->
'\'\'',
'\'startswithbacktick',
'backtick\'inside',
'backtick at the end\''.
'backtick at the end\'',
non200_,
'__', % invalid, even when '_' is actually valid
two_underscores__together_are_not_valid,
bormilan marked this conversation as resolved.
Show resolved Hide resolved
'_something', % invalid because it starts with underscore
'42_invalid_because_it_starts_with_a_number',
'42invalid', %% even without underscores
weDontSupportCamelCaseHere,
not_even_in_a__SUITE.
8 changes: 7 additions & 1 deletion test/examples/pass_atom_naming_convention.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@
for_test() ->
this_is_an_ok_atom,
'and_so_is_this',
'and_this_1_too'.
'and_this_1_too',
elbrujohalcon marked this conversation as resolved.
Show resolved Hide resolved
non_200,
'_', % used by ets/mnesia/etc.
non200, % valid, even without underscores
valid_200even_if_numb3rs_appear_between_letters,
blahblah_SUITE,
x.
26 changes: 13 additions & 13 deletions test/style_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,7 @@ verify_atom_naming_convention(Config) ->
Group = proplists:get_value(group, Config, erl_files),
Ext = proplists:get_value(test_file_ext, Config, "erl"),

BaseRegex = "^([a-z][a-z0-9_]+)$",
BaseRegex = "^[a-z](_?[a-z0-9]+)*(_SUITE)?$",

% pass
PassModule = pass_atom_naming_convention,
Expand Down Expand Up @@ -1337,37 +1337,37 @@ verify_atom_naming_convention(Config) ->
FailModule2 = fail_atom_naming_convention_exception_class,
FailPath2 = atom_to_list(FailModule2) ++ "." ++ Ext,

[_, _, _, _, _, _, _, _, _, _] =
[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] =
elvis_core_apply_rule(Config,
elvis_style,
atom_naming_convention,
#{regex => BaseRegex, enclosed_atoms => same},
FailPath),
[_, _, _, _, _, _, _, _] =
[_, _, _, _, _, _, _, _, _, _, _] =
elvis_core_apply_rule(Config,
elvis_style,
atom_naming_convention,
#{regex => "^([a-zA-Z_]+)$", enclosed_atoms => same},
FailPath),
[_, _] =
[_, _, _, _, _] =
elvis_core_apply_rule(Config,
elvis_style,
atom_naming_convention,
#{regex => "^([a-zA-Z_' \\\\]+)$", enclosed_atoms => same},
FailPath),
[_, _, _, _, _, _, _] =
[_, _, _, _, _, _, _, _, _, _] =
elvis_core_apply_rule(Config,
elvis_style,
atom_naming_convention,
#{regex => "^([a-zA-Z\-_]+)$", enclosed_atoms => same},
FailPath),
[_] =
[_, _, _, _] =
elvis_core_apply_rule(Config,
elvis_style,
atom_naming_convention,
#{regex => "^([a-zA-Z\-_' \\\\]+)$", enclosed_atoms => same},
FailPath),
[] =
[_] =
elvis_core_apply_rule(Config,
elvis_style,
atom_naming_convention,
Expand All @@ -1380,26 +1380,26 @@ verify_atom_naming_convention(Config) ->
#{regex => BaseRegex, ignore => [FailModule]},
FailPath),
KeepRegex = "^([a-zA-Z0-9_]+)$",
[_, _, _, _, _, _, _, _] =
[_, _, _, _, _, _, _, _, _, _, _, _] =
elvis_core_apply_rule(Config,
elvis_style,
atom_naming_convention,
#{regex => KeepRegex, enclosed_atoms => "^([a-z][a-z0-9A-Z_]*)$"},
FailPath),
[_, _, _, _, _, _] =
[_, _, _, _, _, _, _, _, _, _] =
elvis_core_apply_rule(Config,
elvis_style,
atom_naming_convention,
#{regex => KeepRegex,
enclosed_atoms => "^([a-z][a-z0-9A-Z_' \\\\]*)$"},
FailPath),
[_, _, _, _, _, _, _] =
[_, _, _, _, _, _, _, _, _, _, _] =
elvis_core_apply_rule(Config,
elvis_style,
atom_naming_convention,
#{regex => KeepRegex, enclosed_atoms => "^([a-z][\-a-z0-9A-Z_]*)$"},
FailPath),
[_, _, _, _] =
[_, _, _, _, _, _] =
elvis_core_apply_rule(Config,
elvis_style,
atom_naming_convention,
Expand All @@ -1414,15 +1414,15 @@ verify_atom_naming_convention(Config) ->
FailPath2),
_ = case Group of
beam_files -> % 'or_THIS' getting stripped of enclosing '
[_, _, _, _] =
[_, _, _, _, _, _, _, _] =
elvis_core_apply_rule(Config,
elvis_style,
atom_naming_convention,
#{regex => KeepRegex,
enclosed_atoms => "^([\\\\][\-a-z0-9A-Z_' \\\\]*)$"},
FailPath);
erl_files ->
[_, _, _, _, _] =
[_, _, _, _, _, _, _, _, _] =
elvis_core_apply_rule(Config,
elvis_style,
atom_naming_convention,
Expand Down