Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
dffc1e1
Rename god_modules as no_god_modules
paulo-ferraz-oliveira Jun 28, 2025
6f66b03
Rename nesting_level as no_deep_nesting
paulo-ferraz-oliveira Jun 28, 2025
48d7ebc
Rename invalid_dynamic_call as no_invalid_dynamic_calls
paulo-ferraz-oliveira Jun 28, 2025
b644771
Rename used_ignored_variable as no_used_ignored_variables
paulo-ferraz-oliveira Jun 28, 2025
0b71545
Rename macro_names as macro_naming_convention
paulo-ferraz-oliveira Jun 28, 2025
7b09954
Rename consistent_generic_type as generic_type
paulo-ferraz-oliveira Jun 28, 2025
2a0cf79
Rename consistent_variable_casing as variable_casing
paulo-ferraz-oliveira Jun 28, 2025
28031b7
Deprecate old_configuration_format
paulo-ferraz-oliveira Jun 28, 2025
4dc0f5f
Minor fix for better visual results
paulo-ferraz-oliveira Jun 28, 2025
3b7c8a2
Update README examples per more recent output
paulo-ferraz-oliveira Jun 28, 2025
68c796d
Drop src_dirs > dirs normalization as pre-1.0.0 worry
paulo-ferraz-oliveira Jun 28, 2025
3898ff1
Identify behavior-related exports closer to home
paulo-ferraz-oliveira Jun 28, 2025
fbe3649
Make reusable stuff reusable (and tweak variable names)
paulo-ferraz-oliveira Jun 28, 2025
1ff3cde
Drop "map not list" config. normalization as pre-1.0.0 worry
paulo-ferraz-oliveira Jun 28, 2025
bc5c746
Drop seemingly dead code (I searched elvis and rebar3_lint, too)
paulo-ferraz-oliveira Jun 28, 2025
2af71a9
Fix typo
paulo-ferraz-oliveira Jun 29, 2025
61566bb
Renaming for clarity around ruleset/rule
paulo-ferraz-oliveira Jun 29, 2025
de83ab6
Move non-generic stuff out of "generic" module
paulo-ferraz-oliveira Jun 29, 2025
9de5044
Distinguish between rule set and rule namespace
paulo-ferraz-oliveira Jun 30, 2025
85720c5
Make rules opaque
paulo-ferraz-oliveira Jul 3, 2025
a45c376
Tweak the README
paulo-ferraz-oliveira Jul 3, 2025
513fb7f
Tweak some of our types
paulo-ferraz-oliveira Jul 3, 2025
b8d6fed
Act on review comments
paulo-ferraz-oliveira Jul 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 14 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,12 @@ We have only presented results where all files were well-behaved (i.e. they resp
so here's an example of how the output looks when files break some of the rules:

```shell
# ../../test/examples/fail_line_length.erl [FAIL]
- line_length
- Line 14 is too long: " io:format(\"This line is 81 characters long and should be detected, yeah!!!\").".
- Line 20 is too long: " io:format(\"This line is 90 characters long and should be detected!!!!!!!!!!!!!!!!!!\").".
# ../../test/examples/fail_no_tabs.erl [FAIL]
- no_tabs
- Line 6 has a tab at column 0.
- Line 15 has a tab at column 0.
# ../../test/examples/small.erl [OK]
# test/examples/british_behaviour_spelling.erl [FAIL]
- state_record_and_type (https://github.com/inaka/elvis_core/tree/main/doc_rules/elvis_style/state_record_and_type.md)
- This module implements an OTP behavior but is missing a '#state{}' record.
# test/examples/fail_always_shortcircuit.erl [FAIL]
- always_shortcircuit (https://github.com/inaka/elvis_core/tree/main/doc_rules/elvis_style/always_shortcircuit.md)
- At line 5, column 45, unexpected non-shortcircuiting operator 'or' was found; prefer 'orelse'.
```

## Configuration
Expand All @@ -105,9 +102,6 @@ An `elvis.config` file looks something like this:
, #{ dirs => ["."]
, filter => "rebar.config"
, ruleset => rebar_config }
, #{ dirs => ["."]
, filter => "elvis.config"
, ruleset => elvis_config }
]}
% output_format (optional): how to format the output.
% Possible values are 'plain', 'colors' or 'parsable' (default='colors').
Expand All @@ -133,10 +127,13 @@ The `dirs` key is a list that tells `elvis_core` where it should look for the fi

If you want to override the [pre-defined rules](#pre-defined-rules), for a given ruleset, you need
to specify them in a `rules` key which is a list of items with the following structure
`{Module, Function, RuleConfig}`, or `{Module, Function}` - if the rule takes no configuration
`{RuleNamespace, Rule, RuleConfig}`, or `{RuleNamespace, Rule}` - if the rule takes no configuration
values. You can also `disable` certain rules if you want to, by specifying them in the `rules` key
and passing `disable` as a third argument.

`RuleNamespace` is an Erlang module that implements the `elvis_rule` behaviour.
`Rule` is a function exported from `RuleNamespace`.

#### Disabling Rules

**IMPORTANT**: `disable` will only work if you also provided a `ruleset` as shown above.
Expand Down Expand Up @@ -190,10 +187,8 @@ to the one presented by `dialyzer`, like `<file>:<line>:<rule>:<message>`:

<!-- markdownlint-disable MD013 -->
```shell
src/example.erl:1:god_modules:This module has too many functions (56). Consider breaking it into a number of modules.
src/example_a.erl:341:no_debug_call:Remove the debug call to io:format/2 on line 341.
src/example_a.erl:511:used_ignored_variable:Ignored variable is being used on line 511 and column 54.
src/example_a.erl:1252:used_ignored_variable:Ignored variable is being used on line 1252 and column 21.
test/examples/british_behaviour_spelling.erl:-1:state_record_and_type:This module implements an OTP behavior but is missing a '#state{}' record.```
test/examples/fail_always_shortcircuit.erl:5:always_shortcircuit:At line 5, column 45, unexpected non-shortcircuiting operator ''or'' was found; prefer 'orelse'.
```
<!-- markdownlint-enable MD013 -->

Expand Down Expand Up @@ -240,12 +235,11 @@ found in this repository's [RULES.md](https://github.com/inaka/elvis_core/blob/m

### User-defined rules

The implementation of a new rule is a function that takes 3 arguments in the following order:
The implementation of a new rule is a function that takes 2 arguments in the following order:

1. `t:elvis_rule:t()`: the opaque rule to implement
1. `t:elvis_config:config()`: the value of option `config` as found in the
[configuration](#configuration),
1. `t:elvis_file:file()`: the file to be analyzed,
1. `t:erlang:map()`: a configuration map specific to your user-defined rule.

This means you can define rules of your own (user-defined rules) as long as the functions that
implement them respect this interface.
Expand Down
37 changes: 16 additions & 21 deletions RULES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,20 @@ Most, if not all, of the rules will present (opinionated) documentation sections
- [Always Shortcircuit](doc_rules/elvis_style/always_shortcircuit.md)
- [Atom Naming Convention](doc_rules/elvis_style/atom_naming_convention.md)
- [Behaviour Spelling](doc_rules/elvis_style/behaviour_spelling.md)
- [Consistent Generic Type](doc_rules/elvis_style/consistent_generic_type.md)
- [Consistent Variable Casing](doc_rules/elvis_style/consistent_variable_casing.md)
- [Don't Repeat Yourself](doc_rules/elvis_style/dont_repeat_yourself.md)
- [Export Used Types](doc_rules/elvis_style/export_used_types.md)
- [Function Naming Convention](doc_rules/elvis_style/function_naming_convention.md)
- [God Modules](doc_rules/elvis_style/god_modules.md)
- [Generic Type](doc_rules/elvis_style/generic_type.md)
- [Include `ms_transform` for `ets:fun2ms/1`](doc_rules/elvis_style/ms_transform_included.md)
- [Invalid Dynamic Calls](doc_rules/elvis_style/invalid_dynamic_call.md)
- [Line Length](doc_rules/elvis_text_style/line_length.md)
- [Macro Module Names - *deprecated*](doc_rules/elvis_style/macro_module_names.md)
- [Macro Names](doc_rules/elvis_style/macro_names.md)
- [Macro Naming Convention](doc_rules/elvis_style/macro_naming_convention.md)
- [Max Anonymous Function Arity](doc_rules/elvis_style/max_anonymous_function_arity.md)
- [Max Function Arity](doc_rules/elvis_style/max_function_arity.md)
- [Max Function Clause Length](doc_rules/elvis_style/max_function_clause_length.md)
- [Max Function Length](doc_rules/elvis_style/max_function_length.md)
- [Max Module Length](doc_rules/elvis_style/max_module_length.md)
- [Module Naming Convention](doc_rules/elvis_style/module_naming_convention.md)
- [Nesting Level](doc_rules/elvis_style/nesting_level.md)
<!-- markdownlint-disable MD033 -->
- [No <code>$&nbsp;</code>](doc_rules/elvis_style/no_dollar_space.md)
<!-- markdownlint-enable MD033 -->
Expand All @@ -49,11 +45,15 @@ Most, if not all, of the rules will present (opinionated) documentation sections
- [No Catch Expressions](doc_rules/elvis_style/no_catch_expressions.md)
- [No Common Caveats](doc_rules/elvis_style/no_common_caveats_call.md)
- [No Debug Call](doc_rules/elvis_style/no_debug_call.md)
- [No Deep Nesting](doc_rules/elvis_style/no_deep_nesting.md)
- [No God Modules](doc_rules/elvis_style/no_god_modules.md)
- [No If Expression](doc_rules/elvis_style/no_if_expression.md)
- [No Import](doc_rules/elvis_style/no_import.md)
- [No Invalid Dynamic Calls](doc_rules/elvis_style/no_invalid_dynamic_calls.md)
- [No Init Lists](doc_rules/elvis_style/no_init_lists.md)
- [No Macros](doc_rules/elvis_style/no_macros.md)
- [No Match In Condition](doc_rules/elvis_style/no_match_in_condition.md)
- [No Nested Header Files](doc_rules/elvis_style/no_nested_hrls.md)
- [No Nested `try...catch` Blocks](doc_rules/elvis_style/no_nested_try_catch.md)
- [No Operator With Same Values](doc_rules/elvis_style/no_operation_on_same_value.md)
- [No Redundant Blank Lines](doc_rules/elvis_text_style/no_redundant_blank_lines.md)
Expand All @@ -69,14 +69,14 @@ Most, if not all, of the rules will present (opinionated) documentation sections
- [No Throw](doc_rules/elvis_style/no_throw.md)
- [No Trailing Whitespace](doc_rules/elvis_text_style/no_trailing_whitespace.md)
- [No Types](doc_rules/elvis_style/no_types.md)
- [No Nested Header Files](doc_rules/elvis_style/no_nested_hrls.md)
- [No Used Ignored Variables](doc_rules/elvis_style/no_used_ignored_variables.md)
- [Numeric Format](doc_rules/elvis_style/numeric_format.md)
- [Operator Spaces](doc_rules/elvis_style/operator_spaces.md)
- [Param Pattern-Matching](doc_rules/elvis_style/param_pattern_matching.md)
- [Prefer Unquoted Atoms](doc_rules/elvis_text_style/prefer_unquoted_atoms.md)
- [Private Data Types](doc_rules/elvis_style/private_data_types.md)
- [State Record And Type](doc_rules/elvis_style/state_record_and_type.md)
- [Used Ignored Variable](doc_rules/elvis_style/used_ignored_variable.md)
- [Variable Casing](doc_rules/elvis_style/variable_casing.md)
- [Variable Naming Convention](doc_rules/elvis_style/variable_naming_convention.md)

## `.gitignore` rules
Expand All @@ -89,7 +89,7 @@ Most, if not all, of the rules will present (opinionated) documentation sections
- [No Deps `master` `erlang.mk` - *deprecated*](doc_rules/elvis_project/no_deps_master_erlang_mk.md)
- [No Deps `master` `rebar.config` - *deprecated*](doc_rules/elvis_project/no_deps_master_rebar.md)
- [No Deps With Branches](doc_rules/elvis_project/no_branch_deps.md)
- [Old Configuration Format](doc_rules/elvis_project/old_configuration_format.md)
- [Old Configuration Format - *deprecated*](doc_rules/elvis_project/old_configuration_format.md)
- [Protocol For Deps `erlang.mk` - *deprecated*](doc_rules/elvis_project/protocol_for_deps_erlang_mk.md)
- [Protocol For Deps `rebar.config` - *deprecated*](doc_rules/elvis_project/protocol_for_deps_rebar.md)
- [Protocol For Deps](doc_rules/elvis_project/protocol_for_deps.md)
Expand All @@ -102,17 +102,16 @@ rulesets in the configuration file.

The six pre-defined rulesets are:

- `elvis_config`, for elvis configuration files.
- `erl_files`, for Erlang source files (pre-defined rule set).
- `erl_files`, for Erlang source files (pre-defined ruleset).
- `erl_files_strict`, for Erlang source files (all applicable rules).
- `gitignore`, for `.gitignore` files.
- `hrl_files`, for Erlang header files (pre-defined rule set).
- `hrl_files`, for Erlang header files (pre-defined ruleset).
- `hrl_files_strict`, for Erlang header files (all applicable rules).
- `rebar_config`, for rebar configuration files.

Custom rulesets are defined in a `{<ruleset>, #{}}` tuple in `elvis`' configuration. Each key in the
map represents the ruleset name and is mapped to a list of rules as otherwise defined in a standard
ruleset.
Custom rulesets are defined in a `{RuleNamespace, #{}}` tuple in `elvis`' configuration. Each key in
the map represents the ruleset name and is mapped to a list of rules as otherwise defined in a
standard ruleset.

Example configuration with a custom ruleset (named `my_ruleset`):

Expand Down Expand Up @@ -156,7 +155,7 @@ You can always play with the following, but results may not be surprising.

```erlang
-module(mymodule).
-elvis([{elvis_style, nesting_level, #{ level => 4, ignore => [mymodule] }}]).
-elvis([{elvis_style, no_deep_nesting, #{ level => 4, ignore => [mymodule] }}]).
...
```

Expand All @@ -174,7 +173,7 @@ your choice.
It suffices to add the `ignore` list to your rules, as per the example below.

```erlang
-elvis([{elvis_style, invalid_dynamic_call, #{ ignore => [elvis_core]}}]).
-elvis([{elvis_style, no_invalid_dynamic_calls, #{ ignore => [elvis_core]}}]).
-elvis([{elvis_style, no_debug_call, #{ ignore => [elvis_result, elvis_utils]}}]).
```

Expand Down Expand Up @@ -227,10 +226,6 @@ for `.hrl` files.
, filter => "rebar.config"
, ruleset => rebar_config
, rules => [] }
, #{ dirs => ["."]
, filter => "elvis.config"
, ruleset => elvis_config
, rules => [] }
, #{ dirs => ["."]
, filter => ".gitignore"
, ruleset => gitignore }
Expand Down
25 changes: 10 additions & 15 deletions config/elvis-test.config
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
[
{elvis_text_style, line_length, #{limit => 80, skip_comments => false}},
{elvis_text_style, no_tabs},
{elvis_style, macro_names},
{elvis_style, macro_naming_convention},
{elvis_style, operator_spaces, #{
rules => [{right, ","}, {right, "++"}, {left, "++"}]
}},
{elvis_style, nesting_level, #{level => 3}},
{elvis_style, god_modules, #{limit => 25}},
{elvis_style, no_deep_nesting, #{level => 3}},
{elvis_style, no_god_modules, #{limit => 25}},
{elvis_style, no_if_expression},
{elvis_style, invalid_dynamic_call, #{ignore => [elvis]}},
{elvis_style, used_ignored_variable},
{elvis_style, no_invalid_dynamic_calls, #{ignore => [elvis]}},
{elvis_style, no_used_ignored_variables},
{elvis_style, no_behavior_info},
{elvis_style, module_naming_convention, #{
regex => "^([a-z][a-z0-9]*_?)*(_SUITE)?$", ignore => []
Expand All @@ -33,15 +33,15 @@
[
{elvis_text_style, line_length, #{limit => 80, skip_comments => false}},
{elvis_text_style, no_tabs},
{elvis_style, macro_names},
{elvis_style, macro_naming_convention},
{elvis_style, operator_spaces, #{
rules => [{right, ","}, {right, "++"}, {left, "++"}]
}},
{elvis_style, nesting_level, #{level => 3}},
{elvis_style, god_modules, #{limit => 25}},
{elvis_style, no_deep_nesting, #{level => 3}},
{elvis_style, no_god_modules, #{limit => 25}},
{elvis_style, no_if_expression},
{elvis_style, invalid_dynamic_call, #{ignore => [elvis]}},
{elvis_style, used_ignored_variable},
{elvis_style, no_invalid_dynamic_calls, #{ignore => [elvis]}},
{elvis_style, no_used_ignored_variables},
{elvis_style, no_behavior_info},
{elvis_style, module_naming_convention, #{
regex => "^([a-z][a-z0-9]*_?)*(_SUITE)?$", ignore => []
Expand All @@ -60,11 +60,6 @@
{elvis_project, protocol_for_deps, #{ignore => []}}
],
ruleset => rebar_config
},
#{
dirs => ["."],
filter => "elvis.config",
rules => [{elvis_project, old_configuration_format}]
}
]}
]}
Expand Down
5 changes: 0 additions & 5 deletions config/elvis.config
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@
dirs => ["."],
filter => "rebar.config",
ruleset => rebar_config
},
#{
dirs => ["."],
filter => "elvis.config",
ruleset => elvis_config
}
]}
]}
Expand Down
43 changes: 0 additions & 43 deletions config/old/elvis-test-rule-config-list.config

This file was deleted.

24 changes: 0 additions & 24 deletions config/old/elvis-test.config

This file was deleted.

24 changes: 0 additions & 24 deletions config/old/elvis.config

This file was deleted.

13 changes: 4 additions & 9 deletions config/test.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
rules =>
[
{elvis_text_style, line_length, #{limit => 80, skip_comments => false}},
{elvis_style, nesting_level, #{level => 3}},
{elvis_style, invalid_dynamic_call, #{ignore => [elvis]}},
{elvis_style, no_deep_nesting, #{level => 3}},
{elvis_style, no_invalid_dynamic_calls, #{ignore => [elvis]}},
{elvis_style, no_macros},
{elvis_style, param_pattern_matching, #{side => right}}
],
Expand All @@ -26,8 +26,8 @@
rules =>
[
{elvis_text_style, line_length, #{limit => 80, skip_comments => false}},
{elvis_style, nesting_level, #{level => 3}},
{elvis_style, invalid_dynamic_call, #{ignore => [elvis]}},
{elvis_style, no_deep_nesting, #{level => 3}},
{elvis_style, no_invalid_dynamic_calls, #{ignore => [elvis]}},
{elvis_style, no_macros}
],
ruleset => beam_files
Expand All @@ -37,11 +37,6 @@
filter => "rebar.config",
ruleset => rebar_config
},
#{
dirs => ["../../_build/test/lib/elvis_core/test/examples"],
filter => "elvis.config",
ruleset => elvis_config
},
#{
dirs =>
[
Expand Down
Loading
Loading