Skip to content

Commit 4d789c4

Browse files
Merge pull request #317 from paulo-ferraz-oliveira/feature/minor-maintenance-updates
Maintenance updates
2 parents 5cc15a1 + b0167c2 commit 4d789c4

37 files changed

+214
-155
lines changed

.github/workflows/ci.yml

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
11
---
22
name: build
3-
on:
4-
push:
5-
branches:
6-
- main
7-
pull_request:
8-
branches:
9-
- main
3+
on: [push, pull_request]
104
jobs:
115
ci:
126
name: OTP ${{matrix.otp_vsn}} on ${{matrix.os}}
137
runs-on: ${{matrix.os}}
148
strategy:
159
matrix:
16-
otp_vsn: [23, 24, 25]
17-
os: [ubuntu-20.04, windows-latest]
10+
otp_vsn: ['24', '25', '26']
11+
rebar3_vsn: ['3.22']
12+
os: [ubuntu-22.04, windows-2022]
1813
steps:
1914
- uses: actions/checkout@v3
2015
- uses: erlef/setup-beam@v1
2116
id: setup-beam
2217
with:
2318
otp-version: ${{matrix.otp_vsn}}
24-
rebar3-version: '3.20'
19+
rebar3-version: ${{matrix.rebar3_vsn}}
2520
- name: Restore _build
2621
uses: actions/cache@v3
2722
with:
@@ -43,7 +38,7 @@ jobs:
4338
- name: Compile
4439
run: rebar3 compile
4540
- name: Format check
46-
if: ${{ matrix.os == 'ubuntu-20.04' }}
41+
if: ${{ matrix.os == 'ubuntu-22.04' }}
4742
run: rebar3 format --verify
4843
- name: Run test
4944
run: rebar3 test

.github/workflows/lint.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ on: [push, pull_request]
55

66
jobs:
77
md_and_yml:
8-
runs-on: ubuntu-latest
8+
runs-on: ubuntu-22.04
99

1010
steps:
1111
- uses: actions/checkout@v3
1212

1313
# uses .markdownlint.yml for configuration
1414
- name: markdownlint
15-
uses: DavidAnson/markdownlint-cli2-action@v5
15+
uses: DavidAnson/markdownlint-cli2-action@v11
1616
with:
1717
globs: |
1818
LICENSE

.gitignore

+7-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
1-
.eunit
2-
.rebar
3-
deps
4-
ebin
5-
*.o
6-
*.beam
7-
*.plt
81
erl_crash.dump
9-
log*/
10-
_build
2+
_*
3+
doc/
4+
rebar3.crashdump
5+
.rebar3
6+
logs
7+
test/**/*.beam
8+
119
# Ignore elvis escript
1210
elvis
13-
rebar
14-
elvis.d
15-
doc
16-
rebar3.crashdump
17-
.rebar3/
18-
rebar3

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ file.
3333
## Questions?
3434

3535
If you have any questions or general comments regarding how to contribute, please use our public
36-
[hipchat room](http://inaka.net/hipchat).
36+
Erlanger Slack channel: [#elvis](https://erlanger.slack.com/archives/C01073W0E15).

LICENSE

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Apache License
44
Version 2.0, January 2004
5-
http://www.apache.org/licenses/
5+
https://www.apache.org/licenses/
66

77
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
88

@@ -194,7 +194,7 @@
194194
you may not use this file except in compliance with the License.
195195
You may obtain a copy of the License at
196196

197-
http://www.apache.org/licenses/LICENSE-2.0
197+
https://www.apache.org/licenses/LICENSE-2.0
198198

199199
Unless required by applicable law or agreed to in writing, software
200200
distributed under the License is distributed on an "AS IS" BASIS,

README.md

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
# elvis_core [![GitHub Actions CI][ci-img]][ci] [![Erlang Support][support-img]][support]
1+
# elvis_core
22

3-
[ci]: https://github.com/inaka/elvis_core
4-
[ci-img]: https://github.com/inaka/elvis_core/workflows/build/badge.svg
5-
[support]: http://www.erlang.org
6-
[support-img]: https://img.shields.io/badge/Erlang/OTP-23+-blue
3+
[![GitHub Actions CI](https://github.com/inaka/elvis_core/workflows/build/badge.svg)](https://github.com/inaka/elvis_core)
4+
[![Erlang Support](https://img.shields.io/badge/Erlang/OTP-24+-blue)](https://www.erlang.org)
75

86
`elvis_core` is the core library for the [`elvis`](https://github.com/inaka/elvis) Erlang style
97
reviewer. It is also used by [`rebar3_lint`](https://github.com/project-fifo/rebar3_lint) for easier
@@ -59,7 +57,7 @@ current directory. If no configuration is found `{invalid_config, _}` is thrown.
5957
#### Providing configuration as a value
6058

6159
Another option for using `elvis_core` from the shell is to explicitly provide the configuration as
62-
an argument to `rock/1`:
60+
an argument to `elvis_core:rock/1`:
6361

6462
```shell
6563
1> ElvisConfig = [#{dirs => ["src"], filter => "*.erl", rules => []}].
@@ -241,16 +239,16 @@ environment variables, i.e. as they would be found by `application:get_env/2,3`.
241239
### Pre-defined rules
242240

243241
A reference to all pre-defined rules (and some other information) implemented in `elvis_core` can be
244-
found in this repository's [RULES.md](RULES.md).
242+
found in this repository's [RULES.md](https://github.com/inaka/elvis_core/blob/main/RULES.md).
245243

246244
### User-defined rules
247245

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

250-
1. `elvis_config:config()`: the value of option `config` as found in the
248+
1. `t:elvis_config:config()`: the value of option `config` as found in the
251249
[configuration](#configuration),
252-
1. `elvis_file:file()`: the file to be analyzed,
253-
1. `map()`: a configuration map specific to your user-defined rule.
250+
1. `t:elvis_file:file()`: the file to be analyzed,
251+
1. `t:erlang:map()`: a configuration map specific to your user-defined rule.
254252

255253
This means you can define rules of your own (user-defined rules) as long as the functions that
256254
implement them respect this interface.

RULES.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ identified with `(since ...)` for convenience purposes.
4545
- [No Match in Condition](doc_rules/elvis_style/no_match_in_condition.md)
4646
- [No Nested try...catch Blocks](doc_rules/elvis_style/no_nested_try_catch.md)
4747
- [No Single-Clause Case Statements](doc_rules/elvis_style/no_single_clause_case.md)
48-
- [No Space after #](doc_rules/elvis_style/no_space_after_pount.md)
48+
- [No Space after #](doc_rules/elvis_style/no_space_after_pound.md)
4949
- [No Space](doc_rules/elvis_style/no_space.md)
5050
- [No Spec With Records](doc_rules/elvis_style/no_spec_with_records.md)
5151
- [No Specs](doc_rules/elvis_style/no_specs.md)

doc_rules/elvis_style/dont_repeat_yourself.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Don't Repeat Yourself
22

3-
The *Don't Repeat Yourself* ([DRY](http://en.wikipedia.org/wiki/Don't_repeat_yourself)) rule checks
3+
The *Don't Repeat Yourself* ([DRY](https://en.wikipedia.org/wiki/Don't_repeat_yourself)) rule checks
44
if there is repeated code within a module. A piece of code is considered repeated or duplicated when
55
its structure can be found in at least another piece of code in the same module.
66

doc_rules/elvis_style/no_common_caveats_call.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
(since [0.4.0](https://github.com/inaka/elvis_core/releases/tag/0.4.0))
44

5-
The [Erlang Efficiency Guide](http://erlang.org/doc/efficiency_guide/commoncaveats.html) has a list
5+
The [Erlang Efficiency Guide](https://erlang.org/doc/efficiency_guide/commoncaveats.html) has a list
66
of "Common Caveats" suggesting more efficient alternatives to several common functions. This rule
77
provides warnings if you call "inefficient" functions with entirely equivalent (efficient)
88
alternatives.

doc_rules/elvis_style/no_successive_maps.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
(since [2.0.0](https://github.com/inaka/elvis_core/releases/tag/2.0.0))
44

55
The idea behind this rule comes from
6-
[this email](http://erlang.org/pipermail/erlang-questions/2017-April/092112.html) by @kvakvs.
6+
[this email](https://erlang.org/pipermail/erlang-questions/2017-April/092112.html) by @kvakvs.
77
Basically, the warning is emitted if a developer _forgets a comma_ and writes something like the following:
88

99
```erlang
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Operator Spaces
2+
3+
There should be a space in the position (e.g., `right` or `left`) of the operators specified. The
4+
operator can be any string.
5+
6+
> Works on `.beam` file? Not really! (it consumes results Ok, but these might be unexpected)
7+
8+
## Options
9+
10+
- `rules :: [{right | left, string()}].`
11+
- default:
12+
- before [1.5.0](https://github.com/inaka/elvis_core/releases/tag/1.5.0): `[{right, ","},
13+
{right, "++"}, {left, "++"}]`
14+
- since [1.5.0](https://github.com/inaka/elvis_core/releases/tag/1.5.0):
15+
16+
```erlang
17+
[{right, "++"}, {left, "++"}, {right, "="}, {left, "="}, {right, "+"}, {left, "+"},
18+
{right, "-"}, {left, "-"}, {right, "*"}, {left, "*"}, {right, "/"}, {left, "/"},
19+
{right, "=<"}, {left, "=<"}, {right, "<"}, {left, "<"}, {right, ">"}, {left, ">"},
20+
{right, ">="}, {left, ">="}, {right, "=="}, {left, "=="}, {right, "=:="}, {left, "=:="},
21+
{right, "/="}, {left, "/="}, {right, "=/="}, {left, "=/="}, {right, "--"}, {left, "--"},
22+
{right, "=>"}, {left, "=>"}, {right, ":="}, {left, ":="}, {right, "<-"}, {left, "<-"},
23+
{right, "<="}, {left, "<="}, {right, "||"}, {left, "||"}, {right, "|"}, {left, "|"},
24+
{right, "::"}, {left, "::"}, {right, "->"}, {left, "->"}, {right, ","}]
25+
```
26+
27+
## Example
28+
29+
```erlang
30+
{elvis_style, operator_spaces, #{ rules => [{right, ","}
31+
, {right, "++"}
32+
, {left, "++"}
33+
]
34+
}}
35+
```

rebar.config

+34-37
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,58 @@
1-
%% -*- mode: erlang;erlang-indent-level: 2;indent-tabs-mode: nil -*-
2-
%% ex: ts=4 sw=4 ft=erlang et
1+
%% == Compiler and Profiles ==
32

4-
%% == Erlang Compiler ==
3+
{erl_opts,
4+
[warn_unused_import, warn_export_vars, warnings_as_errors, verbose, report, debug_info]}.
55

6-
%% Erlang compiler options
7-
{erl_opts, [debug_info, warn_export_vars, warn_missing_spec, warn_unused_import]}.
6+
{minimum_otp_vsn, "23"}.
87

98
{profiles,
109
[{test,
1110
[{extra_src_dirs, ["test/examples"]},
1211
{deps, [{meck, "0.9.2"}]},
1312
{erl_opts, [nowarn_missing_spec, nowarn_export_all]},
14-
{dialyzer, [{warnings, [no_return, unmatched_returns, error_handling]}]}]}]}.
13+
{dialyzer, [{warnings, [no_return, error_handling]}, {plt_extra_apps, [common_test]}]},
14+
{ct_opts, [{sys_config, ["./config/test.config"]}, {logdir, "./logs"}, {verbose, true}]},
15+
{cover_enabled, true},
16+
{cover_opts, [verbose]}]}]}.
1517

16-
{ct_opts, [{sys_config, ["./config/test.config"]}, {logdir, "./logs"}, {verbose, true}]}.
18+
{alias, [{test, [compile, format, hank, xref, dialyzer, ct, cover, ex_doc]}]}.
1719

18-
%% == Cover ==
19-
20-
{cover_enabled, true}.
21-
22-
{cover_opts, [verbose]}.
20+
{shell, [{config, "config/test.config"}]}.
2321

24-
%% == Dependencies ==
22+
%% == Dependencies and plugins ==
2523

26-
{deps, [{zipper, "1.0.1"}, {katana_code, "~> 2.0.2"}]}.
24+
{deps, [{zipper, "1.0.1"}, {katana_code, "~> 2.1.0"}]}.
2725

28-
%% == Dialyzer ==
26+
{project_plugins,
27+
[{rebar3_hank, "~> 1.4.0"},
28+
{rebar3_hex, "~> 7.0.7"},
29+
{rebar3_format, "~> 1.3.0"},
30+
{rebar3_ex_doc, "0.2.18"}]}.
2931

30-
{dialyzer,
31-
[{warnings, [no_return, unmatched_returns, error_handling, unknown]},
32-
{plt_apps, top_level_deps},
33-
{plt_extra_apps, [kernel, stdlib]},
34-
{plt_location, local}]}.
32+
%% == Documentation ==
3533

36-
{shell, [{config, "config/test.config"}]}.
34+
{ex_doc,
35+
[{source_url, <<"https://github.com/inaka/elvis_core">>},
36+
{extras, [<<"README.md">>, <<"LICENSE">>]},
37+
{main, <<"readme">>}]}.
3738

38-
%% == xref ==
39+
{hex, [{doc, #{provider => ex_doc}}]}.
3940

40-
{xref_checks, [undefined_function_calls, locals_not_used, deprecated_function_calls]}.
41+
%% == Format ==
4142

42-
%% == Aliases ==
43+
{format,
44+
[{files,
45+
["config/**/*.config", "src/**/*.app.src", "src/**/*.erl", "test/*.erl", "*.config"]}]}.
4346

44-
{alias, [{test, [format, xref, dialyzer, hank, ct, cover, edoc]}]}.
47+
%% == Hank ==
4548

46-
{project_plugins,
47-
[{rebar3_hex, "~> 7.0.1"}, {rebar3_format, "~> 1.2.0"}, {rebar3_hank, "~> 1.3.0"}]}.
49+
{hank, [{ignore, ["test/*/**"]}]}.
4850

49-
%% == hank ==
51+
%% == Dialyzer + XRef ==
5052

51-
{hank,
52-
[{ignore,
53-
[{"test/*/**", unnecessary_function_arguments},
54-
{"test/*/**", unused_macros},
55-
{"test/*/**", unused_callbacks}]}]}.
53+
{dialyzer, [{warnings, [no_return, unmatched_returns, error_handling, unknown]}]}.
5654

57-
%% == format ==
55+
{xref_checks,
56+
[undefined_function_calls, deprecated_function_calls, deprecated_functions]}.
5857

59-
{format,
60-
[{files,
61-
["config/**/*.config", "src/**/*.app.src", "src/**/*.erl", "test/*.erl", "*.config"]}]}.
58+
{xref_extra_paths, ["test/**"]}.

src/elvis_core.app.src

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
{modules, [elvis_core, elvis_config, elvis_result, elvis_utils, elvis_style]},
88
{registered, []},
99
{licenses, ["Apache 2.0"]},
10-
{links, [{"Github", "https://github.com/inaka/elvis_core"}]},
10+
{links, [{"GitHub", "https://github.com/inaka/elvis_core"}]},
1111
{build_tools, ["rebar3"]}]}.

src/elvis_core.erl

+8-1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ main([]) ->
142142
%%% Private
143143
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
144144

145+
%% @private
145146
-spec combine_results(ok | {fail, [elvis_result:file()]},
146147
ok | {fail, [elvis_result:file()]}) ->
147148
ok | {fail, [elvis_result:file()]}.
@@ -157,6 +158,7 @@ apply_rules_and_print(Config, File) ->
157158
elvis_result:print_results(Results),
158159
Results.
159160

161+
%% @private
160162
-spec apply_rules(elvis_config:configs() | elvis_config:config(),
161163
File :: elvis_file:file()) ->
162164
elvis_result:file().
@@ -168,25 +170,29 @@ apply_rules(Config, File) ->
168170
lists:foldl(fun apply_rule/2, Acc, merge_rules({file, ParseTree}, lists:flatten(Rules))),
169171
elvis_result:new(file, File, RulesResults).
170172

173+
%% @private
171174
merge_rules({file, ParseTree}, ElvisConfigRules) ->
172175
ElvisAttrs =
173176
elvis_code:find(fun is_elvis_attr/1, ParseTree, #{traverse => content, mode => node}),
174177
ElvisAttrRules = elvis_attr_rules(ElvisAttrs),
175178
elvis_config:merge_rules(ElvisAttrRules, ElvisConfigRules).
176179

180+
%% @private
177181
is_elvis_attr(Node) ->
178182
ktn_code:type(Node) =:= elvis.
179183

184+
%% @private
180185
elvis_attr_rules([] = _ElvisAttrs) ->
181186
[];
182187
elvis_attr_rules(ElvisAttrs) ->
183188
[Rule || ElvisAttr <- ElvisAttrs, Rule <- ktn_code:attr(value, ElvisAttr)].
184189

190+
%% @private
185191
-spec apply_rule({Mod, Fun} | {Mod, Fun, RuleCfg}, {Results, ElvisCfg, File}) -> Result
186192
when Mod :: module(),
187193
Fun :: atom(),
188194
RuleCfg :: rule_config(),
189-
Results :: [elvis_result:rule()],
195+
Results :: [elvis_result:rule() | elvis_result:elvis_error()],
190196
ElvisCfg :: elvis_config:config(),
191197
File :: elvis_file:file(),
192198
Result :: {Results, ElvisCfg, File}.
@@ -223,6 +229,7 @@ apply_rule({Module, Function, ConfigArgs}, {Result, Config, File}) ->
223229
end,
224230
{[RuleResult | Result], Config, File}.
225231

232+
%% @private
226233
%% @doc Process a tules configuration argument and converts it to a map.
227234
ensure_config_map(_, _, Map) when is_map(Map) ->
228235
Map;

0 commit comments

Comments
 (0)