From 2eaece10869f98bbb3ac65f0f1bfd86e61d00b31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mil=C3=A1n=20B=C3=B3r?= Date: Wed, 11 Sep 2024 20:07:15 +0200 Subject: [PATCH 1/4] fix(#312): fix atom naming convention regex --- src/elvis_style.erl | 2 +- test/examples/fail_atom_naming_convention.erl | 3 ++- test/examples/pass_atom_naming_convention.erl | 3 ++- test/style_SUITE.erl | 16 ++++++++-------- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/elvis_style.erl b/src/elvis_style.erl index 14311707..8749b5be 100644 --- a/src/elvis_style.erl +++ b/src/elvis_style.erl @@ -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]*_?)*[a-z0-9]+(_SUITE)?$", enclosed_atoms => ".*"}; %% Not restrictive. Those who want more restrictions can set it like "^[^_]*$" default(numeric_format) -> #{regex => ".*", diff --git a/test/examples/fail_atom_naming_convention.erl b/test/examples/fail_atom_naming_convention.erl index 7cf7f503..5975d71b 100644 --- a/test/examples/fail_atom_naming_convention.erl +++ b/test/examples/fail_atom_naming_convention.erl @@ -12,4 +12,5 @@ for_test() -> '\'\'', '\'startswithbacktick', 'backtick\'inside', - 'backtick at the end\''. + 'backtick at the end\'', + non200_. diff --git a/test/examples/pass_atom_naming_convention.erl b/test/examples/pass_atom_naming_convention.erl index d650e0a3..7766df84 100644 --- a/test/examples/pass_atom_naming_convention.erl +++ b/test/examples/pass_atom_naming_convention.erl @@ -5,4 +5,5 @@ for_test() -> this_is_an_ok_atom, 'and_so_is_this', - 'and_this_1_too'. + 'and_this_1_too', + non_200. diff --git a/test/style_SUITE.erl b/test/style_SUITE.erl index c59f94e7..399d1582 100644 --- a/test/style_SUITE.erl +++ b/test/style_SUITE.erl @@ -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_]+[a-z0-9])$", % pass PassModule = pass_atom_naming_convention, @@ -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, @@ -1422,7 +1422,7 @@ verify_atom_naming_convention(Config) -> enclosed_atoms => "^([\\\\][\-a-z0-9A-Z_' \\\\]*)$"}, FailPath); erl_files -> - [_, _, _, _, _] = + [_, _, _, _, _, _] = elvis_core_apply_rule(Config, elvis_style, atom_naming_convention, From 9a7b2b439c3cd7a73515baaed663c0e8225af9ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mil=C3=A1n=20B=C3=B3r?= Date: Wed, 11 Sep 2024 20:18:30 +0200 Subject: [PATCH 2/4] fix(#312): fix test --- test/style_SUITE.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/style_SUITE.erl b/test/style_SUITE.erl index 399d1582..b0d4d96b 100644 --- a/test/style_SUITE.erl +++ b/test/style_SUITE.erl @@ -1422,7 +1422,7 @@ verify_atom_naming_convention(Config) -> enclosed_atoms => "^([\\\\][\-a-z0-9A-Z_' \\\\]*)$"}, FailPath); erl_files -> - [_, _, _, _, _, _] = + [_, _, _, _, _] = elvis_core_apply_rule(Config, elvis_style, atom_naming_convention, From 61e038cfb3c3736e2affb19a457847c58793c18d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mil=C3=A1n=20B=C3=B3r?= Date: Thu, 12 Sep 2024 20:37:37 +0200 Subject: [PATCH 3/4] fix regex, and add new atoms to the test --- src/elvis_style.erl | 2 +- test/examples/fail_atom_naming_convention.erl | 8 ++++++- test/examples/pass_atom_naming_convention.erl | 5 +++- test/style_SUITE.erl | 24 +++++++++---------- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/elvis_style.erl b/src/elvis_style.erl index 8749b5be..8cfde9cb 100644 --- a/src/elvis_style.erl +++ b/src/elvis_style.erl @@ -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]*_?)*[a-z0-9]+(_SUITE)?$", enclosed_atoms => ".*"}; + #{regex => "^[a-z]+((_?[a-z0-9])*[a-z0-9]+)*(_SUITE)?$", enclosed_atoms => ".*"}; %% Not restrictive. Those who want more restrictions can set it like "^[^_]*$" default(numeric_format) -> #{regex => ".*", diff --git a/test/examples/fail_atom_naming_convention.erl b/test/examples/fail_atom_naming_convention.erl index 5975d71b..70945fc7 100644 --- a/test/examples/fail_atom_naming_convention.erl +++ b/test/examples/fail_atom_naming_convention.erl @@ -13,4 +13,10 @@ for_test() -> '\'startswithbacktick', 'backtick\'inside', 'backtick at the end\'', - non200_. + non200_, + '__', % invalid, even when '_' is actually valid + two_underscores__together_are_not_valid, + '_something', % invalid because it starts with underscore + '42_invalid_because_it_starts_with_a_number', + '42invalid', %% even without underscores + weDontSupportCamelCaseHere. diff --git a/test/examples/pass_atom_naming_convention.erl b/test/examples/pass_atom_naming_convention.erl index 7766df84..8174f746 100644 --- a/test/examples/pass_atom_naming_convention.erl +++ b/test/examples/pass_atom_naming_convention.erl @@ -6,4 +6,7 @@ for_test() -> this_is_an_ok_atom, 'and_so_is_this', 'and_this_1_too', - non_200. + non_200, + '_', % used by ets/mnesia/etc. + non200, % valid, even without underscores + valid_200even_if_numb3rs_appear_between_letters. diff --git a/test/style_SUITE.erl b/test/style_SUITE.erl index b0d4d96b..af9361f2 100644 --- a/test/style_SUITE.erl +++ b/test/style_SUITE.erl @@ -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_]+[a-z0-9])$", + BaseRegex = "^[a-z]+((_?[a-z0-9])*[a-z0-9]+)*$", % pass PassModule = pass_atom_naming_convention, @@ -1337,31 +1337,31 @@ 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, @@ -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, @@ -1414,7 +1414,7 @@ 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, @@ -1422,7 +1422,7 @@ verify_atom_naming_convention(Config) -> enclosed_atoms => "^([\\\\][\-a-z0-9A-Z_' \\\\]*)$"}, FailPath); erl_files -> - [_, _, _, _, _] = + [_, _, _, _, _, _, _, _, _] = elvis_core_apply_rule(Config, elvis_style, atom_naming_convention, From 79f53ce254557ca202d2c5c4c4dafda9bd240723 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mil=C3=A1n=20B=C3=B3r?= Date: Mon, 16 Sep 2024 15:57:02 +0200 Subject: [PATCH 4/4] fix regex once more --- src/elvis_style.erl | 2 +- test/examples/fail_atom_naming_convention.erl | 3 ++- test/examples/pass_atom_naming_convention.erl | 4 +++- test/style_SUITE.erl | 4 ++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/elvis_style.erl b/src/elvis_style.erl index 8cfde9cb..52fe1e7a 100644 --- a/src/elvis_style.erl +++ b/src/elvis_style.erl @@ -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])*[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 => ".*", diff --git a/test/examples/fail_atom_naming_convention.erl b/test/examples/fail_atom_naming_convention.erl index 70945fc7..2d75f84f 100644 --- a/test/examples/fail_atom_naming_convention.erl +++ b/test/examples/fail_atom_naming_convention.erl @@ -19,4 +19,5 @@ for_test() -> '_something', % invalid because it starts with underscore '42_invalid_because_it_starts_with_a_number', '42invalid', %% even without underscores - weDontSupportCamelCaseHere. + weDontSupportCamelCaseHere, + not_even_in_a__SUITE. diff --git a/test/examples/pass_atom_naming_convention.erl b/test/examples/pass_atom_naming_convention.erl index 8174f746..9536ef86 100644 --- a/test/examples/pass_atom_naming_convention.erl +++ b/test/examples/pass_atom_naming_convention.erl @@ -9,4 +9,6 @@ for_test() -> non_200, '_', % used by ets/mnesia/etc. non200, % valid, even without underscores - valid_200even_if_numb3rs_appear_between_letters. + valid_200even_if_numb3rs_appear_between_letters, + blahblah_SUITE, + x. diff --git a/test/style_SUITE.erl b/test/style_SUITE.erl index af9361f2..10b1a1e6 100644 --- a/test/style_SUITE.erl +++ b/test/style_SUITE.erl @@ -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])*[a-z0-9]+)*$", + BaseRegex = "^[a-z](_?[a-z0-9]+)*(_SUITE)?$", % pass PassModule = pass_atom_naming_convention, @@ -1337,7 +1337,7 @@ 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,