From 7967ffe4525e5eb2f5d0c224c2b8484d9dc3fb3f Mon Sep 17 00:00:00 2001 From: "Paulo F. Oliveira" Date: Tue, 16 Jan 2024 16:29:17 +0000 Subject: [PATCH 1/2] Simplify and sort rules for rulesets We simplify via list comprehensions We sort for readability Note: this brings no relevant code changes --- src/elvis_rulesets.erl | 174 ++++++++++++++++++++--------------------- 1 file changed, 87 insertions(+), 87 deletions(-) diff --git a/src/elvis_rulesets.erl b/src/elvis_rulesets.erl index 4f82b17..1e50431 100644 --- a/src/elvis_rulesets.erl +++ b/src/elvis_rulesets.erl @@ -13,105 +13,105 @@ set_rulesets(RuleSets) -> -spec rules(Group :: atom()) -> [elvis_core:rule()]. rules(hrl_files) -> lists:map(fun({Mod, Rule}) -> {Mod, Rule, apply(Mod, default, [Rule])} end, - [{elvis_text_style, line_length}, - {elvis_text_style, no_tabs}, - {elvis_text_style, no_trailing_whitespace}, - {elvis_style, macro_names}, - {elvis_style, macro_module_names}, - {elvis_style, no_block_expressions}, - {elvis_style, operator_spaces}, - {elvis_style, no_space_after_pound}, - {elvis_style, no_space}, - {elvis_style, nesting_level}, - {elvis_style, no_if_expression}, - {elvis_style, used_ignored_variable}, - {elvis_style, no_behavior_info}, - {elvis_style, no_debug_call}, - {elvis_style, variable_naming_convention}, - {elvis_style, consistent_variable_casing}, - {elvis_style, no_nested_try_catch}, - {elvis_style, no_successive_maps}, - {elvis_style, atom_naming_convention}, - {elvis_style, no_throw}, - {elvis_style, no_dollar_space}, - {elvis_style, no_author}, - {elvis_style, no_import}, - {elvis_style, no_catch_expressions}, - {elvis_style, no_single_clause_case}, - {elvis_style, no_match_in_condition}, - {elvis_style, numeric_format}, - {elvis_style, no_specs}, - {elvis_style, no_types}]); + [{elvis_text_style, Rule} || Rule <- [line_length, no_tabs, no_trailing_whitespace]] + ++ [{elvis_style, Rule} + || Rule + <- [atom_naming_convention, + consistent_variable_casing, + macro_module_names, + macro_names, + nesting_level, + no_author, + no_behavior_info, + no_block_expressions, + no_catch_expressions, + no_debug_call, + no_dollar_space, + no_if_expression, + no_import, + no_match_in_condition, + no_nested_try_catch, + no_single_clause_case, + no_space, + no_space_after_pound, + no_specs, + no_successive_maps, + no_throw, + no_types, + numeric_format, + operator_spaces, + used_ignored_variable, + variable_naming_convention]]); rules(erl_files) -> lists:map(fun({Mod, Rule}) -> {Mod, Rule, apply(Mod, default, [Rule])} end, - [{elvis_text_style, line_length}, - {elvis_text_style, no_tabs}, - {elvis_text_style, no_trailing_whitespace}, - {elvis_style, macro_names}, - {elvis_style, macro_module_names}, - {elvis_style, no_block_expressions}, - {elvis_style, operator_spaces}, - {elvis_style, no_space_after_pound}, - {elvis_style, no_space}, - {elvis_style, nesting_level}, - {elvis_style, god_modules}, - {elvis_style, no_if_expression}, - {elvis_style, invalid_dynamic_call}, - {elvis_style, used_ignored_variable}, - {elvis_style, no_behavior_info}, - {elvis_style, module_naming_convention}, - {elvis_style, function_naming_convention}, - {elvis_style, no_spec_with_records}, - {elvis_style, dont_repeat_yourself}, - {elvis_style, no_debug_call}, - {elvis_style, variable_naming_convention}, - {elvis_style, consistent_variable_casing}, - {elvis_style, no_nested_try_catch}, - {elvis_style, no_successive_maps}, - {elvis_style, atom_naming_convention}, - {elvis_style, no_throw}, - {elvis_style, no_dollar_space}, - {elvis_style, no_author}, - {elvis_style, no_import}, - {elvis_style, no_catch_expressions}, - {elvis_style, no_single_clause_case}, - {elvis_style, no_match_in_condition}, - {elvis_style, numeric_format}, - {elvis_style, behaviour_spelling}, - {elvis_style, export_used_types}, - {elvis_style, max_function_arity}, - {elvis_style, max_anonymous_function_arity}, - {elvis_style, param_pattern_matching}, - {elvis_style, private_data_types}]); + [{elvis_text_style, Rule} || Rule <- [line_length, no_tabs, no_trailing_whitespace]] + ++ [{elvis_style, Rule} + || Rule + <- [atom_naming_convention, + behaviour_spelling, + consistent_variable_casing, + dont_repeat_yourself, + export_used_types, + function_naming_convention, + god_modules, + invalid_dynamic_call, + macro_module_names, + macro_names, + max_anonymous_function_arity, + max_function_arity, + module_naming_convention, + nesting_level, + no_author, + no_behavior_info, + no_block_expressions, + no_catch_expressions, + no_debug_call, + no_dollar_space, + no_if_expression, + no_import, + no_match_in_condition, + no_nested_try_catch, + no_single_clause_case, + no_space, + no_space_after_pound, + no_spec_with_records, + no_successive_maps, + no_throw, + numeric_format, + operator_spaces, + param_pattern_matching, + private_data_types, + used_ignored_variable, + variable_naming_convention]]); rules(beam_files) -> lists:map(fun(Rule) -> {elvis_style, Rule, elvis_style:default(Rule)} end, - [nesting_level, + [atom_naming_convention, + behaviour_spelling, + consistent_variable_casing, + dont_repeat_yourself, + export_used_types, + function_naming_convention, god_modules, - no_if_expression, invalid_dynamic_call, - used_ignored_variable, + max_anonymous_function_arity, + max_function_arity, module_naming_convention, - function_naming_convention, - no_spec_with_records, - dont_repeat_yourself, + nesting_level, + no_author, + no_catch_expressions, no_debug_call, - variable_naming_convention, - consistent_variable_casing, + no_if_expression, + no_import, + no_match_in_condition, no_nested_try_catch, + no_single_clause_case, + no_spec_with_records, no_successive_maps, - atom_naming_convention, no_throw, - no_author, - no_import, - no_catch_expressions, - no_single_clause_case, - no_match_in_condition, - behaviour_spelling, - export_used_types, - max_function_arity, - max_anonymous_function_arity, param_pattern_matching, - private_data_types]); + private_data_types, + used_ignored_variable, + variable_naming_convention]); rules(rebar_config) -> lists:map(fun(Rule) -> {elvis_project, Rule, elvis_project:default(Rule)} end, [no_branch_deps, protocol_for_deps]); From a1184205d3634f49105f748f4555da2d9cd4d68a Mon Sep 17 00:00:00 2001 From: "Paulo F. Oliveira" Date: Tue, 16 Jan 2024 16:51:22 +0000 Subject: [PATCH 2/2] Implement new ruleset erl_files_strict --- RULES.md | 5 +++-- src/elvis_rulesets.erl | 13 +++++++++++++ test/elvis_SUITE.erl | 18 +++++++++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/RULES.md b/RULES.md index 8970c6e..da5561e 100644 --- a/RULES.md +++ b/RULES.md @@ -78,10 +78,11 @@ Rulesets in `elvis` are used to group individual rules together and can save a l `elvis` currently has five pre-defined rulesets, but gives you the ability to specify custom rulesets in the configuration file. -The five pre-defined rulesets are: +The six pre-defined rulesets are: - `elvis_config`, for elvis configuration files. -- `erl_files`, for Erlang source files. +- `erl_files`, for Erlang source files (pre-defined rule set). +- `erl_files_strict`, for Erlang source files (all available rules). - `hrl_files`, for Erlang header files. - `makefiles`, for Makefiles. - `rebar_config`, for rebar configuration files. diff --git a/src/elvis_rulesets.erl b/src/elvis_rulesets.erl index 1e50431..7d73ff2 100644 --- a/src/elvis_rulesets.erl +++ b/src/elvis_rulesets.erl @@ -83,6 +83,19 @@ rules(erl_files) -> private_data_types, used_ignored_variable, variable_naming_convention]]); +rules(erl_files_strict) -> + rules(erl_files) + ++ lists:map(fun({Mod, Rule}) -> {Mod, Rule, apply(Mod, default, [Rule])} end, + [{elvis_style, Rule} + || Rule + <- [always_shortcircuit, + consistent_generic_type, + max_function_length, + max_module_length, + no_call, + no_common_caveats_call, + no_macros, + state_record_and_type]]); rules(beam_files) -> lists:map(fun(Rule) -> {elvis_style, Rule, elvis_style:default(Rule)} end, [atom_naming_convention, diff --git a/test/elvis_SUITE.erl b/test/elvis_SUITE.erl index 7d398f5..54c0e58 100644 --- a/test/elvis_SUITE.erl +++ b/test/elvis_SUITE.erl @@ -12,7 +12,7 @@ rock_with_rule_groups/1, rock_this_skipping_files/1, rock_this_not_skipping_files/1, rock_with_umbrella_apps/1, custom_ruleset/1, hrl_ruleset/1, throw_configuration/1, find_file_and_check_src/1, find_file_with_ignore/1, invalid_file/1, to_string/1, - chunk_fold/1]). + chunk_fold/1, erl_files_strict_ruleset/1]). -define(EXCLUDED_FUNS, [module_info, all, test, init_per_suite, end_per_suite, chunk_fold_task]). @@ -391,6 +391,22 @@ hrl_ruleset(_Config) -> elvis_core:rock(ElvisConfig), ok. +-spec erl_files_strict_ruleset(config()) -> any(). +erl_files_strict_ruleset(_Config) -> + DefinedRules = elvis_rulesets:rules(erl_files_strict), + DefinedRuleNames = [DefinedRuleName || {elvis_style, DefinedRuleName, _} <- DefinedRules], + DefinedRuleNamesSorted = lists:sort(DefinedRuleNames), + + FunctionsNotErlRuleNames = [no_specs, no_types, option], + AllRuleNames = + [Function + || {Function, Arity} <- elvis_style:module_info(exports), + Arity =:= 3, + not lists:member(Function, FunctionsNotErlRuleNames)], + AllRuleNamesSorted = lists:sort(AllRuleNames), + + true = AllRuleNamesSorted =:= DefinedRuleNamesSorted. + -spec throw_configuration(config()) -> any(). throw_configuration(_Config) -> Filename = "./elvis.config",