Skip to content

Commit cb60dcd

Browse files
Merge pull request #330 from kivra-pauoli/feature/erl_files_strict_ruleset
New ruleset: `erl_files_strict`
2 parents dfaa84e + a118420 commit cb60dcd

File tree

3 files changed

+120
-90
lines changed

3 files changed

+120
-90
lines changed

RULES.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ Rulesets in `elvis` are used to group individual rules together and can save a l
7878
`elvis` currently has five pre-defined rulesets, but gives you the ability to specify custom
7979
rulesets in the configuration file.
8080

81-
The five pre-defined rulesets are:
81+
The six pre-defined rulesets are:
8282

8383
- `elvis_config`, for elvis configuration files.
84-
- `erl_files`, for Erlang source files.
84+
- `erl_files`, for Erlang source files (pre-defined rule set).
85+
- `erl_files_strict`, for Erlang source files (all available rules).
8586
- `hrl_files`, for Erlang header files.
8687
- `makefiles`, for Makefiles.
8788
- `rebar_config`, for rebar configuration files.

src/elvis_rulesets.erl

+100-87
Original file line numberDiff line numberDiff line change
@@ -13,105 +13,118 @@ set_rulesets(RuleSets) ->
1313
-spec rules(Group :: atom()) -> [elvis_core:rule()].
1414
rules(hrl_files) ->
1515
lists:map(fun({Mod, Rule}) -> {Mod, Rule, apply(Mod, default, [Rule])} end,
16-
[{elvis_text_style, line_length},
17-
{elvis_text_style, no_tabs},
18-
{elvis_text_style, no_trailing_whitespace},
19-
{elvis_style, macro_names},
20-
{elvis_style, macro_module_names},
21-
{elvis_style, no_block_expressions},
22-
{elvis_style, operator_spaces},
23-
{elvis_style, no_space_after_pound},
24-
{elvis_style, no_space},
25-
{elvis_style, nesting_level},
26-
{elvis_style, no_if_expression},
27-
{elvis_style, used_ignored_variable},
28-
{elvis_style, no_behavior_info},
29-
{elvis_style, no_debug_call},
30-
{elvis_style, variable_naming_convention},
31-
{elvis_style, consistent_variable_casing},
32-
{elvis_style, no_nested_try_catch},
33-
{elvis_style, no_successive_maps},
34-
{elvis_style, atom_naming_convention},
35-
{elvis_style, no_throw},
36-
{elvis_style, no_dollar_space},
37-
{elvis_style, no_author},
38-
{elvis_style, no_import},
39-
{elvis_style, no_catch_expressions},
40-
{elvis_style, no_single_clause_case},
41-
{elvis_style, no_match_in_condition},
42-
{elvis_style, numeric_format},
43-
{elvis_style, no_specs},
44-
{elvis_style, no_types}]);
16+
[{elvis_text_style, Rule} || Rule <- [line_length, no_tabs, no_trailing_whitespace]]
17+
++ [{elvis_style, Rule}
18+
|| Rule
19+
<- [atom_naming_convention,
20+
consistent_variable_casing,
21+
macro_module_names,
22+
macro_names,
23+
nesting_level,
24+
no_author,
25+
no_behavior_info,
26+
no_block_expressions,
27+
no_catch_expressions,
28+
no_debug_call,
29+
no_dollar_space,
30+
no_if_expression,
31+
no_import,
32+
no_match_in_condition,
33+
no_nested_try_catch,
34+
no_single_clause_case,
35+
no_space,
36+
no_space_after_pound,
37+
no_specs,
38+
no_successive_maps,
39+
no_throw,
40+
no_types,
41+
numeric_format,
42+
operator_spaces,
43+
used_ignored_variable,
44+
variable_naming_convention]]);
4545
rules(erl_files) ->
4646
lists:map(fun({Mod, Rule}) -> {Mod, Rule, apply(Mod, default, [Rule])} end,
47-
[{elvis_text_style, line_length},
48-
{elvis_text_style, no_tabs},
49-
{elvis_text_style, no_trailing_whitespace},
50-
{elvis_style, macro_names},
51-
{elvis_style, macro_module_names},
52-
{elvis_style, no_block_expressions},
53-
{elvis_style, operator_spaces},
54-
{elvis_style, no_space_after_pound},
55-
{elvis_style, no_space},
56-
{elvis_style, nesting_level},
57-
{elvis_style, god_modules},
58-
{elvis_style, no_if_expression},
59-
{elvis_style, invalid_dynamic_call},
60-
{elvis_style, used_ignored_variable},
61-
{elvis_style, no_behavior_info},
62-
{elvis_style, module_naming_convention},
63-
{elvis_style, function_naming_convention},
64-
{elvis_style, no_spec_with_records},
65-
{elvis_style, dont_repeat_yourself},
66-
{elvis_style, no_debug_call},
67-
{elvis_style, variable_naming_convention},
68-
{elvis_style, consistent_variable_casing},
69-
{elvis_style, no_nested_try_catch},
70-
{elvis_style, no_successive_maps},
71-
{elvis_style, atom_naming_convention},
72-
{elvis_style, no_throw},
73-
{elvis_style, no_dollar_space},
74-
{elvis_style, no_author},
75-
{elvis_style, no_import},
76-
{elvis_style, no_catch_expressions},
77-
{elvis_style, no_single_clause_case},
78-
{elvis_style, no_match_in_condition},
79-
{elvis_style, numeric_format},
80-
{elvis_style, behaviour_spelling},
81-
{elvis_style, export_used_types},
82-
{elvis_style, max_function_arity},
83-
{elvis_style, max_anonymous_function_arity},
84-
{elvis_style, param_pattern_matching},
85-
{elvis_style, private_data_types}]);
47+
[{elvis_text_style, Rule} || Rule <- [line_length, no_tabs, no_trailing_whitespace]]
48+
++ [{elvis_style, Rule}
49+
|| Rule
50+
<- [atom_naming_convention,
51+
behaviour_spelling,
52+
consistent_variable_casing,
53+
dont_repeat_yourself,
54+
export_used_types,
55+
function_naming_convention,
56+
god_modules,
57+
invalid_dynamic_call,
58+
macro_module_names,
59+
macro_names,
60+
max_anonymous_function_arity,
61+
max_function_arity,
62+
module_naming_convention,
63+
nesting_level,
64+
no_author,
65+
no_behavior_info,
66+
no_block_expressions,
67+
no_catch_expressions,
68+
no_debug_call,
69+
no_dollar_space,
70+
no_if_expression,
71+
no_import,
72+
no_match_in_condition,
73+
no_nested_try_catch,
74+
no_single_clause_case,
75+
no_space,
76+
no_space_after_pound,
77+
no_spec_with_records,
78+
no_successive_maps,
79+
no_throw,
80+
numeric_format,
81+
operator_spaces,
82+
param_pattern_matching,
83+
private_data_types,
84+
used_ignored_variable,
85+
variable_naming_convention]]);
86+
rules(erl_files_strict) ->
87+
rules(erl_files)
88+
++ lists:map(fun({Mod, Rule}) -> {Mod, Rule, apply(Mod, default, [Rule])} end,
89+
[{elvis_style, Rule}
90+
|| Rule
91+
<- [always_shortcircuit,
92+
consistent_generic_type,
93+
max_function_length,
94+
max_module_length,
95+
no_call,
96+
no_common_caveats_call,
97+
no_macros,
98+
state_record_and_type]]);
8699
rules(beam_files) ->
87100
lists:map(fun(Rule) -> {elvis_style, Rule, elvis_style:default(Rule)} end,
88-
[nesting_level,
101+
[atom_naming_convention,
102+
behaviour_spelling,
103+
consistent_variable_casing,
104+
dont_repeat_yourself,
105+
export_used_types,
106+
function_naming_convention,
89107
god_modules,
90-
no_if_expression,
91108
invalid_dynamic_call,
92-
used_ignored_variable,
109+
max_anonymous_function_arity,
110+
max_function_arity,
93111
module_naming_convention,
94-
function_naming_convention,
95-
no_spec_with_records,
96-
dont_repeat_yourself,
112+
nesting_level,
113+
no_author,
114+
no_catch_expressions,
97115
no_debug_call,
98-
variable_naming_convention,
99-
consistent_variable_casing,
116+
no_if_expression,
117+
no_import,
118+
no_match_in_condition,
100119
no_nested_try_catch,
120+
no_single_clause_case,
121+
no_spec_with_records,
101122
no_successive_maps,
102-
atom_naming_convention,
103123
no_throw,
104-
no_author,
105-
no_import,
106-
no_catch_expressions,
107-
no_single_clause_case,
108-
no_match_in_condition,
109-
behaviour_spelling,
110-
export_used_types,
111-
max_function_arity,
112-
max_anonymous_function_arity,
113124
param_pattern_matching,
114-
private_data_types]);
125+
private_data_types,
126+
used_ignored_variable,
127+
variable_naming_convention]);
115128
rules(rebar_config) ->
116129
lists:map(fun(Rule) -> {elvis_project, Rule, elvis_project:default(Rule)} end,
117130
[no_branch_deps, protocol_for_deps]);

test/elvis_SUITE.erl

+17-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
rock_with_rule_groups/1, rock_this_skipping_files/1, rock_this_not_skipping_files/1,
1313
rock_with_umbrella_apps/1, custom_ruleset/1, hrl_ruleset/1, throw_configuration/1,
1414
find_file_and_check_src/1, find_file_with_ignore/1, invalid_file/1, to_string/1,
15-
chunk_fold/1]).
15+
chunk_fold/1, erl_files_strict_ruleset/1]).
1616

1717
-define(EXCLUDED_FUNS,
1818
[module_info, all, test, init_per_suite, end_per_suite, chunk_fold_task]).
@@ -391,6 +391,22 @@ hrl_ruleset(_Config) ->
391391
elvis_core:rock(ElvisConfig),
392392
ok.
393393

394+
-spec erl_files_strict_ruleset(config()) -> any().
395+
erl_files_strict_ruleset(_Config) ->
396+
DefinedRules = elvis_rulesets:rules(erl_files_strict),
397+
DefinedRuleNames = [DefinedRuleName || {elvis_style, DefinedRuleName, _} <- DefinedRules],
398+
DefinedRuleNamesSorted = lists:sort(DefinedRuleNames),
399+
400+
FunctionsNotErlRuleNames = [no_specs, no_types, option],
401+
AllRuleNames =
402+
[Function
403+
|| {Function, Arity} <- elvis_style:module_info(exports),
404+
Arity =:= 3,
405+
not lists:member(Function, FunctionsNotErlRuleNames)],
406+
AllRuleNamesSorted = lists:sort(AllRuleNames),
407+
408+
true = AllRuleNamesSorted =:= DefinedRuleNamesSorted.
409+
394410
-spec throw_configuration(config()) -> any().
395411
throw_configuration(_Config) ->
396412
Filename = "./elvis.config",

0 commit comments

Comments
 (0)