Skip to content

Commit

Permalink
Implement new ruleset erl_files_strict
Browse files Browse the repository at this point in the history
  • Loading branch information
kivra-pauoli committed Jan 16, 2024
1 parent 7967ffe commit a118420
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 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
13 changes: 13 additions & 0 deletions src/elvis_rulesets.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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 a118420

Please sign in to comment.