Skip to content

Commit

Permalink
Merge pull request #330 from kivra-pauoli/feature/erl_files_strict_ru…
Browse files Browse the repository at this point in the history
…leset

New ruleset: `erl_files_strict`
  • Loading branch information
elbrujohalcon authored Jan 17, 2024
2 parents dfaa84e + a118420 commit cb60dcd
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 90 deletions.
5 changes: 3 additions & 2 deletions RULES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
187 changes: 100 additions & 87 deletions src/elvis_rulesets.erl
Original file line number Diff line number Diff line change
Expand Up @@ -13,105 +13,118 @@ 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(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,
[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]);
Expand Down
18 changes: 17 additions & 1 deletion test/elvis_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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]).
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit cb60dcd

Please sign in to comment.