-
Notifications
You must be signed in to change notification settings - Fork 58
New rulesets: hrl_files_strict and beam_files_strict
#453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
fb0933b
Document `beam_files` and upcoming `beam_files_strict`
paulo-ferraz-oliveira 05c9c4e
Signal hrl_files (and upcoming hrl_files_strict) better
paulo-ferraz-oliveira ec3dc54
Make it easier to maintain and reason on
paulo-ferraz-oliveira b928672
Remove test that makes less sense now we're composing stuff
paulo-ferraz-oliveira 73101a2
"Pay" the price of making it more consistent (or tweaking it)
paulo-ferraz-oliveira 261adb5
Act on further test results
paulo-ferraz-oliveira de86f85
Tweak it because even if available it might not be applicable
paulo-ferraz-oliveira 0126453
Remove unnecessary config. option
paulo-ferraz-oliveira a3a6549
Fix doc
paulo-ferraz-oliveira b4da99a
Have elvis_ruleset (was elvis_rulesets) be a behaviour
paulo-ferraz-oliveira 5845454
Expand list comprehensions to ease readability
paulo-ferraz-oliveira ce65177
Sort it
paulo-ferraz-oliveira File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,217 @@ | ||
| -module(elvis_ruleset). | ||
|
|
||
| -format(#{inline_items => none}). | ||
|
|
||
| -export([rules/1, set_rulesets/1]). | ||
| -export([default/2]). | ||
|
|
||
| -callback default(RuleName :: atom()) -> DefaultRuleConfig :: #{atom() := term()}. | ||
|
|
||
| -spec default(Module :: module(), RuleName :: atom()) -> DefaultRuleConfig :: #{atom() := term()}. | ||
| default(Module, RuleName) -> | ||
| Module:default(RuleName). | ||
|
|
||
| -spec set_rulesets(#{atom() => list()}) -> ok. | ||
| set_rulesets(RuleSets) -> | ||
| Tid = ensure_clean_table(), | ||
| lists:foreach( | ||
| fun({Name, Rules}) -> true = ets:insert(Tid, {Name, Rules}) end, | ||
| maps:to_list(RuleSets) | ||
| ). | ||
|
|
||
| -spec rules(Group :: atom()) -> [elvis_core:rule()]. | ||
| rules(Group) -> | ||
| Rules = | ||
| case Group of | ||
| gitignore -> | ||
| gitignore_rules(); | ||
| hrl_files -> | ||
| hrl_files_rules(); | ||
| hrl_files_strict -> | ||
| hrl_files_strict_rules(); | ||
| erl_files -> | ||
| erl_files_rules(); | ||
| erl_files_strict -> | ||
| erl_files_strict_rules(); | ||
| beam_files -> | ||
| beam_files_rules(); | ||
| beam_files_strict -> | ||
| beam_files_strict_rules(); | ||
| rebar_config -> | ||
| rebar_config_rules(); | ||
| elvis_config -> | ||
| elvis_config_rules(); | ||
| _ -> | ||
| try | ||
| ets:lookup_element(?MODULE, Group, 2) | ||
| catch | ||
| error:badarg -> | ||
| [] | ||
| end | ||
| end, | ||
| lists:map( | ||
| fun({Mod, Rule}) -> {Mod, Rule, default(Mod, Rule)} end, | ||
| Rules | ||
| ). | ||
|
|
||
| ensure_clean_table() -> | ||
| case ets:info(?MODULE) of | ||
| undefined -> | ||
| ets:new(?MODULE, [set, named_table, {keypos, 1}, public]); | ||
| _ -> | ||
| true = ets:delete_all_objects(?MODULE), | ||
| ?MODULE | ||
| end. | ||
|
|
||
| gitignore_rules() -> | ||
| [ | ||
| {elvis_gitignore, forbidden_patterns}, | ||
| {elvis_gitignore, required_patterns} | ||
| ]. | ||
|
|
||
| hrl_files_rules() -> | ||
| (erl_files_rules() ++ hrl_only_files_rules()) -- doesnt_work_on_hrl_files(). | ||
|
|
||
| hrl_only_files_rules() -> | ||
| [ | ||
| {elvis_style, no_nested_hrls}, | ||
| {elvis_style, no_specs}, | ||
| {elvis_style, no_types} | ||
| ]. | ||
|
|
||
| hrl_files_strict_rules() -> | ||
| erl_files_strict_rules() -- doesnt_work_on_hrl_files(). | ||
|
|
||
| doesnt_work_on_hrl_files() -> | ||
| [ | ||
| {elvis_style, behaviour_spelling}, | ||
| {elvis_style, dont_repeat_yourself}, | ||
| {elvis_style, export_used_types}, | ||
| {elvis_style, function_naming_convention}, | ||
| {elvis_style, god_modules}, | ||
| {elvis_style, invalid_dynamic_call}, | ||
| {elvis_style, max_anonymous_function_arity}, | ||
| {elvis_style, max_function_clause_length}, | ||
| {elvis_style, max_function_length}, | ||
| {elvis_style, ms_transform_included}, | ||
| {elvis_style, no_call}, | ||
| {elvis_style, no_common_caveats_call}, | ||
| {elvis_style, no_init_lists}, | ||
| {elvis_style, no_macros}, | ||
| {elvis_style, no_spec_with_records}, | ||
| {elvis_style, param_pattern_matching}, | ||
| {elvis_style, private_data_types}, | ||
| {elvis_style, state_record_and_type} | ||
| ]. | ||
|
|
||
| erl_files_rules() -> | ||
| elvis_style_rules() ++ elvis_text_style_rules(). | ||
|
|
||
| elvis_style_rules() -> | ||
| [ | ||
| {elvis_style, atom_naming_convention}, | ||
| {elvis_style, behaviour_spelling}, | ||
| {elvis_style, consistent_variable_casing}, | ||
| {elvis_style, dont_repeat_yourself}, | ||
| {elvis_style, export_used_types}, | ||
| {elvis_style, function_naming_convention}, | ||
| {elvis_style, god_modules}, | ||
| {elvis_style, invalid_dynamic_call}, | ||
| {elvis_style, macro_module_names}, | ||
| {elvis_style, macro_names}, | ||
| {elvis_style, max_anonymous_function_arity}, | ||
| {elvis_style, max_function_arity}, | ||
| {elvis_style, module_naming_convention}, | ||
| {elvis_style, nesting_level}, | ||
| {elvis_style, no_author}, | ||
| {elvis_style, no_behavior_info}, | ||
| {elvis_style, no_block_expressions}, | ||
| {elvis_style, no_boolean_in_comparison}, | ||
| {elvis_style, no_catch_expressions}, | ||
| {elvis_style, no_debug_call}, | ||
| {elvis_style, no_dollar_space}, | ||
| {elvis_style, no_if_expression}, | ||
| {elvis_style, no_import}, | ||
| {elvis_style, no_match_in_condition}, | ||
| {elvis_style, no_nested_try_catch}, | ||
| {elvis_style, no_operation_on_same_value}, | ||
| {elvis_style, no_single_clause_case}, | ||
| {elvis_style, no_single_match_maybe}, | ||
| {elvis_style, no_space_after_pound}, | ||
| {elvis_style, no_space}, | ||
| {elvis_style, no_spec_with_records}, | ||
| {elvis_style, no_successive_maps}, | ||
| {elvis_style, no_throw}, | ||
| {elvis_style, numeric_format}, | ||
| {elvis_style, operator_spaces}, | ||
| {elvis_style, param_pattern_matching}, | ||
| {elvis_style, private_data_types}, | ||
| {elvis_style, used_ignored_variable}, | ||
| {elvis_style, variable_naming_convention} | ||
| ]. | ||
|
|
||
| elvis_text_style_rules() -> | ||
| [ | ||
| {elvis_text_style, line_length}, | ||
| {elvis_text_style, no_tabs}, | ||
| {elvis_text_style, no_trailing_whitespace} | ||
| ]. | ||
|
|
||
| erl_files_strict_rules() -> | ||
| erl_files_rules() ++ elvis_style_stricter_rules() ++ elvis_text_style_stricter_rules(). | ||
|
|
||
| elvis_style_stricter_rules() -> | ||
| [ | ||
| {elvis_style, always_shortcircuit}, | ||
| {elvis_style, consistent_generic_type}, | ||
| {elvis_style, max_function_clause_length}, | ||
| {elvis_style, max_function_length}, | ||
| {elvis_style, max_module_length}, | ||
| {elvis_style, ms_transform_included}, | ||
| {elvis_style, no_call}, | ||
| {elvis_style, no_common_caveats_call}, | ||
| {elvis_style, no_init_lists}, | ||
| {elvis_style, no_macros}, | ||
| {elvis_style, state_record_and_type} | ||
| ]. | ||
|
|
||
| elvis_text_style_stricter_rules() -> | ||
| [ | ||
| {elvis_text_style, no_redundant_blank_lines}, | ||
| {elvis_text_style, prefer_unquoted_atoms} | ||
| ]. | ||
|
|
||
| beam_files_rules() -> | ||
| erl_files_rules() -- doesnt_work_on_beam_files(). | ||
|
|
||
| beam_files_strict_rules() -> | ||
| erl_files_strict_rules() -- doesnt_work_on_beam_files(). | ||
|
|
||
| doesnt_work_on_beam_files() -> | ||
| not_on_beam() ++ elvis_text_style_rules() ++ elvis_text_style_stricter_rules(). | ||
|
|
||
| not_on_beam() -> | ||
| [ | ||
| {elvis_style, macro_module_names}, | ||
| {elvis_style, macro_names}, | ||
| {elvis_style, max_function_clause_length}, | ||
| {elvis_style, max_function_length}, | ||
| {elvis_style, max_module_length}, | ||
| {elvis_style, no_dollar_space}, | ||
| {elvis_style, no_macros}, | ||
| {elvis_style, no_space_after_pound}, | ||
| {elvis_style, no_space}, | ||
| {elvis_style, numeric_format}, | ||
| {elvis_style, operator_spaces} | ||
| ]. | ||
|
|
||
| rebar_config_rules() -> | ||
| [ | ||
| {elvis_project, no_branch_deps}, | ||
| {elvis_project, protocol_for_deps} | ||
| ]. | ||
|
|
||
| elvis_config_rules() -> | ||
| [ | ||
| {elvis_project, old_configuration_format} | ||
| ]. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.