Skip to content

Commit b453328

Browse files
author
Brujo Benavides
committed
Merge pull request #102 from inaka/jfacorro.18.no.deps.master
[Closes #18] No deps in revision 'master'.
2 parents 4079ff5 + c3aaad8 commit b453328

22 files changed

Lines changed: 570 additions & 139 deletions

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ ERLC_OPTS += +warn_export_vars +warn_exported_vars +warn_missing_spec +warn_unty
2222
# Commont Test Config
2323

2424
TEST_ERLC_OPTS += +'{parse_transform, lager_transform}'
25-
CT_SUITES = elvis rules git
25+
CT_SUITES = elvis style project git
2626
CT_OPTS = -cover test/elvis.coverspec -erl_args -config config/test.config
2727

2828
# Builds the elvis escript.
@@ -31,4 +31,4 @@ escript: all
3131
./elvis help
3232

3333
shell: app
34-
erl -pa ebin -pa deps/*/ebin -s sync -s elvis -s lager -config config/app.config
34+
erl -pa ebin -pa deps/*/ebin -s sync -s elvis -s lager -config config/elvis.config

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ define rules of your own as long as the functions that implement them respect
166166
this arity.
167167

168168
There's currently no default configuration for `elvis`, but in the meantime
169-
you can take the one in `config/app.config` as a starting point.
169+
you can take the one in `config/elvis.config` as a starting point.
170170

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

config/elvis-test.config

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,36 @@
33
elvis,
44
[
55
{config,
6-
#{src_dirs => ["../../src"],
7-
rules => [{elvis_style, line_length, [80]},
8-
{elvis_style, no_tabs, []},
9-
{elvis_style, macro_names, []},
10-
{elvis_style, macro_module_names, []},
11-
{elvis_style, operator_spaces, [{right, ","},
12-
{right, "++"},
13-
{left, "++"}]},
14-
{elvis_style, nesting_level, [3]},
15-
{elvis_style, god_modules, [25]},
16-
{elvis_style, no_if_expression, []},
17-
{elvis_style, invalid_dynamic_call, [elvis]},
18-
{elvis_style, used_ignored_variable, []},
19-
{elvis_style, no_behavior_info, []},
20-
{
21-
elvis_style,
22-
module_naming_convention,
23-
["^([a-z][a-z0-9]*_?)*(_SUITE)?$", []]
24-
}
25-
]
6+
[#{src_dirs => ["../../src"],
7+
rules => [{elvis_style, line_length, [80]},
8+
{elvis_style, no_tabs, []},
9+
{elvis_style, macro_names, []},
10+
{elvis_style, macro_module_names, []},
11+
{elvis_style, operator_spaces, [{right, ","},
12+
{right, "++"},
13+
{left, "++"}]},
14+
{elvis_style, nesting_level, [3]},
15+
{elvis_style, god_modules, [25]},
16+
{elvis_style, no_if_expression, []},
17+
{elvis_style, invalid_dynamic_call, [elvis]},
18+
{elvis_style, used_ignored_variable, []},
19+
{elvis_style, no_behavior_info, []},
20+
{
21+
elvis_style,
22+
module_naming_convention,
23+
["^([a-z][a-z0-9]*_?)*(_SUITE)?$", []]
24+
}
25+
]
26+
},
27+
#{dirs => ["."],
28+
filter => "Makefile",
29+
rules => [{elvis_project, no_deps_master_erlang_mk, []}]
30+
},
31+
#{dirs => ["."],
32+
filter => "rebar.config",
33+
rules => [{elvis_project, no_deps_master_rebar, []}]
2634
}
35+
]
2736
}
2837
]
2938
}

config/elvis.config

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,37 @@
33
elvis,
44
[
55
{config,
6-
#{src_dirs => ["src"],
7-
rules => [{elvis_style, line_length, [80]},
8-
{elvis_style, no_tabs, []},
9-
{elvis_style, macro_names, []},
10-
{elvis_style, macro_module_names, []},
11-
{elvis_style, operator_spaces, [{right, ","},
12-
{right, "++"},
13-
{left, "++"}]},
14-
{elvis_style, nesting_level, [3]},
15-
{elvis_style, god_modules, [25]},
16-
{elvis_style, no_if_expression, []},
17-
{elvis_style, invalid_dynamic_call, [elvis]},
18-
{elvis_style, used_ignored_variable, []},
19-
{elvis_style, no_behavior_info, []},
20-
{
21-
elvis_style,
22-
module_naming_convention,
23-
["^([a-z][a-z0-9]*_?)*(_SUITE)?$", []]
24-
}
25-
]
6+
[#{dirs => ["src"],
7+
filter => "*.erl",
8+
rules => [{elvis_style, line_length, [80]},
9+
{elvis_style, no_tabs, []},
10+
{elvis_style, macro_names, []},
11+
{elvis_style, macro_module_names, []},
12+
{elvis_style, operator_spaces, [{right, ","},
13+
{right, "++"},
14+
{left, "++"}]},
15+
{elvis_style, nesting_level, [3]},
16+
{elvis_style, god_modules, [25]},
17+
{elvis_style, no_if_expression, []},
18+
{elvis_style, invalid_dynamic_call, [elvis]},
19+
{elvis_style, used_ignored_variable, []},
20+
{elvis_style, no_behavior_info, []},
21+
{
22+
elvis_style,
23+
module_naming_convention,
24+
["^([a-z][a-z0-9]*_?)*(_SUITE)?$", []]
25+
}
26+
]
27+
},
28+
#{dirs => ["."],
29+
filter => "Makefile",
30+
rules => [{elvis_project, no_deps_master_erlang_mk, []}]
31+
},
32+
#{dirs => ["."],
33+
filter => "rebar.config",
34+
rules => [{elvis_project, no_deps_master_rebar, []}]
2635
}
36+
]
2737
}
2838
]
2939
}

config/old/elvis-test.config

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[
2+
{
3+
elvis,
4+
[
5+
{config,
6+
#{src_dirs => ["../../src"],
7+
rules => [{elvis_style, line_length, [80]},
8+
{elvis_style, no_tabs, []},
9+
{elvis_style, macro_names, []},
10+
{elvis_style, macro_module_names, []},
11+
{elvis_style, operator_spaces, [{right, ","},
12+
{right, "++"},
13+
{left, "++"}]},
14+
{elvis_style, nesting_level, [3]},
15+
{elvis_style, god_modules, [25]},
16+
{elvis_style, no_if_expression, []},
17+
{elvis_style, invalid_dynamic_call, [elvis]},
18+
{elvis_style, used_ignored_variable, []},
19+
{elvis_style, no_behavior_info, []},
20+
{
21+
elvis_style,
22+
module_naming_convention,
23+
["^([a-z][a-z0-9]*_?)*(_SUITE)?$", []]
24+
}
25+
]
26+
}
27+
}
28+
]
29+
}
30+
].

config/test.config

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,37 @@
33
elvis,
44
[
55
{config,
6-
#{src_dirs => ["../../test/examples"],
7-
rules => [{elvis_style, line_length, [80]},
8-
{elvis_style, no_tabs, []},
9-
{elvis_style, macro_names, []},
10-
{elvis_style, macro_module_names, []},
11-
{elvis_style, operator_spaces, [{right, ","},
12-
{right, "++"},
13-
{left, "++"}]},
14-
{elvis_style, nesting_level, [3]},
15-
{elvis_style, god_modules, [25]},
16-
{elvis_style, no_if_expression, []},
17-
{elvis_style, invalid_dynamic_call, [elvis]},
18-
{elvis_style, used_ignored_variable, []},
19-
{elvis_style, no_behavior_info, []},
20-
{
21-
elvis_style,
22-
module_naming_convention,
23-
["^([a-z][a-z0-9]*_?)*(_SUITE)?$", []]
24-
}
25-
]
6+
[#{dirs => ["../../test/examples"],
7+
filter => "*.erl",
8+
rules => [{elvis_style, line_length, [80]},
9+
{elvis_style, no_tabs, []},
10+
{elvis_style, macro_names, []},
11+
{elvis_style, macro_module_names, []},
12+
{elvis_style, operator_spaces, [{right, ","},
13+
{right, "++"},
14+
{left, "++"}]},
15+
{elvis_style, nesting_level, [3]},
16+
{elvis_style, god_modules, [25]},
17+
{elvis_style, no_if_expression, []},
18+
{elvis_style, invalid_dynamic_call, [elvis]},
19+
{elvis_style, used_ignored_variable, []},
20+
{elvis_style, no_behavior_info, []},
21+
{
22+
elvis_style,
23+
module_naming_convention,
24+
["^([a-z][a-z0-9]*_?)*(_SUITE)?$", []]
25+
}
26+
]
27+
},
28+
#{dirs => ["."],
29+
filter => "Makefile",
30+
rules => [{elvis_project, no_deps_master_erlang_mk, []}]
31+
},
32+
#{dirs => ["."],
33+
filter => "rebar.config",
34+
rules => [{elvis_project, no_deps_master_rebar, []}]
2635
}
36+
]
2737
}
2838
]
2939
}

erlang.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ else
539539
endif
540540

541541
TEST_ERLC_OPTS ?= +debug_info +warn_export_vars +warn_shadow_vars +warn_obsolete_guard
542-
TEST_ERLC_OPTS += -DTEST=1 -DEXTRA=1 +'{parse_transform, eunit_autoexport}'
542+
TEST_ERLC_OPTS += -DTEST=1 -DEXTRA=1
543543

544544
# Core targets.
545545

src/elvis.erl

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ rock() ->
4747
Config = elvis_config:default(),
4848
rock(Config).
4949

50-
-spec rock(elvis_config:config()) -> ok | {fail, elvis_result:file()}.
50+
-spec rock(elvis_config:config()) -> ok | {fail, [elvis_result:file()]}.
51+
rock(Config) when is_list(Config) ->
52+
Results = lists:map(fun rock/1, Config),
53+
lists:foldl(fun combine_results/2, ok, Results);
5154
rock(Config = #{files := Files, rules := _Rules}) ->
5255
elvis_utils:info("Loading files...~n"),
5356
Fun = fun (File) ->
@@ -64,10 +67,15 @@ rock(Config = #{files := Files, rules := _Rules}) ->
6467
fail -> {fail, Results};
6568
ok -> ok
6669
end;
67-
rock(Config = #{src_dirs := SrcDirs, rules := _Rules}) ->
68-
Files = elvis_utils:find_files(SrcDirs),
69-
70-
rock(Config#{files => Files});
70+
rock(Config = #{dirs := _Dirs, rules := _Rules}) ->
71+
NewConfig = elvis_config:resolve_files(Config),
72+
rock(NewConfig);
73+
rock(Config = #{src_dirs := Dirs}) ->
74+
%% NOTE: Provided for backwards compatibility.
75+
%% Rename 'src_dirs' key to 'dirs'.
76+
Config1 = maps:remove(src_dirs, Config),
77+
Config2 = Config1#{dirs => Dirs},
78+
rock(Config2);
7179
rock(Config) ->
7280
throw({invalid_config, Config}).
7381

@@ -76,9 +84,7 @@ rock(Config) ->
7684
-spec git_hook(elvis_config:config()) -> ok.
7785
git_hook(Config) ->
7886
Files = elvis_git:staged_files(),
79-
ErlFiles = elvis_utils:filter_files(Files),
80-
81-
NewConfig = Config#{files => ErlFiles},
87+
NewConfig = elvis_config:resolve_files(Config, Files),
8288

8389
case rock(NewConfig) of
8490
{fail, _} -> elvis_utils:erlang_halt(1);
@@ -102,6 +108,16 @@ webhook(Credentials, Request) ->
102108
%%% Private
103109
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104110

111+
-spec combine_results(ok | {fail, [elvis_result:file()]},
112+
ok | {fail, [elvis_result:file()]}) ->
113+
ok | {fail, [elvis_result:file()]}.
114+
combine_results(ok, Acc) ->
115+
Acc;
116+
combine_results(Item, ok) ->
117+
Item;
118+
combine_results({fail, ItemResults}, {fail, AccResults}) ->
119+
{fail, ItemResults ++ AccResults}.
120+
105121
-spec apply_rules(elvis_config:config(), elvis_utils:file()) ->
106122
elvis_result:file().
107123
apply_rules(Config = #{rules := Rules}, File) ->

src/elvis_code.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
-spec parse_tree(elvis_config:config(), string() | binary()) ->
6565
[{ok | error, erl_parse:abstract_form()}].
6666
parse_tree(Config, Source) ->
67-
IncludeDirs = elvis_utils:maps_get(src_dirs, Config, []),
67+
IncludeDirs = elvis_config:dirs(Config),
6868
SourceStr = elvis_utils:to_str(Source),
6969
ScanOpts = [text, return_comments],
7070
{ok, Tokens, _} = erl_scan:string(SourceStr, {1, 1}, ScanOpts),

0 commit comments

Comments
 (0)