Skip to content

Commit

Permalink
Merge pull request #21 from inaka/harenson.323.update-documentation-t…
Browse files Browse the repository at this point in the history
…o-include-new-default-configuration-feature

[Fix #323] Add documentation for default configuration feature
  • Loading branch information
igaray committed Jan 13, 2016
2 parents 59cdaa9 + 5be4cd7 commit 207464d
Showing 1 changed file with 32 additions and 21 deletions.
53 changes: 32 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,28 +102,21 @@ in the root directory:
elvis,
[
{config,
[#{dirs => ["src", "test"],
[#{dirs => ["src"],
filter => "*.erl",
rules => [{elvis_style, line_length, #{limit => 80}},
{elvis_style, no_tabs},
{elvis_style, no_trailing_whitespace},
{elvis_style, macro_names},
{elvis_style, macro_module_names},
{elvis_style, operator_spaces, #{rules => [{right, ","},
{right, "++"},
{left, "++"}]}
}
]
ruleset => erl_files
},
#{dirs => ["."],
filter => "Makefile",
rules => [{elvis_project, no_deps_master_erlang_mk, #{ignore => []}},
{elvis_project, protocol_for_deps_erlang_mk, #{ignore => []}}]
ruleset => makefiles
},
#{dirs => ["."],
filter => "rebar.config",
rules => [{elvis_project, no_deps_master_rebar, #{ignore => []}},
{elvis_project, protocol_for_deps_rebar, #{ignore => []}}]
ruleset => rebar_config
},
#{dirs => ["."],
filter => "elvis.config",
ruleset => elvis_config
}
]
},
Expand All @@ -138,19 +131,37 @@ in the root directory:
```

The `dirs` key is a list that indicates where `elvis` should look for the
files that match `filter`, which will be run through each of the rules
specified by the `rules` entry, which is a list of items with the following
structure `{Module, Function, RuleConfig}` or `{Module, Function}` if the rule
takes no configuration values.
files that match `filter`, which will be run through each of the default rules
in the specified `ruleset`, which is an *atom*. If you want to override the
[default rules](https://github.com/inaka/elvis_core/blob/master/src/elvis_rulesets.erl)
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 values. You can also
`disable` certain rules if you want to just by specifying the rule in the `rules`
key and passing `disable` as its third parameter.

Let's say you like your files to have a maximum of 90 characters per line and
also you like to use tabs instead of spaces, so you need to override `erl_files`
`ruleset` default `rules` as follows:

```erlang
...
#{dirs => ["src"],
filter => "*.erl",
rules => [{elvis_style, line_length, #{limit => 90}}, %% change default line_length limit from 80 to 90
{elvis_style, no_tabs, disable}], %% disable no_tabs rule
ruleset => erl_files
},
...
```

The implementation of a rule is just a function that takes 3 arguments: `elvis`'s
`config` entry from its [configuration](#configuration); the file to be
analyzed; and a configuration map specified for the rule. This means you can
define rules of your own as long as the functions that implement them respect
this arity.

There's currently no default configuration for `elvis`, but in the meantime
you can take the one in `config/elvis.config` as a starting point.
You can find the default `elvis` configuration file at `config/elvis.config`.

The GitHub configuration parameters `github_user` and `github_password` are
required only when `elvis` is used as a [webhook](#webhook).
Expand Down

0 comments on commit 207464d

Please sign in to comment.