Skip to content

Commit

Permalink
Issue warnings on empty folders
Browse files Browse the repository at this point in the history
Helps keep a trimmed down elvis.config

Example output:
Warning: Searching for files in ["test/examples/2"] yielded none. Update your configuration.
  • Loading branch information
paulo-ferraz-oliveira committed Jan 12, 2021
1 parent 1a284cb commit 1cfbd98
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/elvis_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ resolve_files(RuleGroup, Files) ->
Dirs = dirs(RuleGroup),
Ignore = ignore(RuleGroup),
FilteredFiles = elvis_file:filter_files(Files, Dirs, Filter, Ignore),
_ = case FilteredFiles of
[] ->
Error = elvis_result:new(warn, "Searching for files in ~p yielded none. "
"Update your configuration.", [Dirs]),
ok = elvis_result:print_results([Error]);
_ ->
ok
end,
RuleGroup#{files => FilteredFiles}.

%% @doc Takes a configuration and finds all files according to its 'dirs'
Expand Down
16 changes: 13 additions & 3 deletions src/elvis_result.erl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
error_msg => string(),
info => list()
}.
-type elvis_warn() ::
#{
warn_msg => string(),
info => list()
}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Public
Expand All @@ -63,15 +68,18 @@
-spec new(item, string(), [term()]) -> item()
; (rule, atom(), [item()]) -> rule()
; (file, elvis_file:file(), [elvis_error() | rule()]) -> file()
; (error, string(), string()) -> elvis_error().
; (error, string(), string()) -> elvis_error()
; (warn, string(), string()) -> elvis_warn().
new(item, Msg, Info) ->
new(item, Msg, Info, 0);
new(rule, Name, Results) ->
#{name => Name, items => Results};
new(file, #{path := Path}, Rules) ->
#{file => Path, rules => Rules};
new(error, Msg, Info) ->
#{error_msg => Msg, info => Info}.
#{error_msg => Msg, info => Info};
new(warn, Msg, Info) ->
#{warn_msg => Msg, info => Info}.

-spec new(item, string(), [term()], integer()) -> item().
new(item, Msg, Info, LineNum) ->
Expand Down Expand Up @@ -165,7 +173,9 @@ print_item(_Format, _File, _Name, []) ->
ok.

print_error(#{error_msg := Msg, info := Info}) ->
elvis_utils:error_prn(Msg, Info).
elvis_utils:error_prn(Msg, Info);
print_error(#{warn_msg := Msg, info := Info}) ->
elvis_utils:warn_prn(Msg, Info).

-spec status([file() | rule()]) -> ok | fail.
status([]) ->
Expand Down
7 changes: 7 additions & 0 deletions src/elvis_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
error/2,
error_prn/1,
error_prn/2,
warn_prn/2,
parse_colors/1
]).

Expand Down Expand Up @@ -162,6 +163,11 @@ error_prn(Message, Args) ->
ColoredMessage = "{{red}}Error: {{reset}}" ++ Message ++ "{{reset}}~n",
print(ColoredMessage, Args).

-spec warn_prn(string(), [term()]) -> ok.
warn_prn(Message, Args) ->
ColoredMessage = "{{magenta}}Warning: {{reset}}" ++ Message ++ "{{reset}}~n",
print(ColoredMessage, Args).

-spec print_info(string(), [term()]) -> ok.
print_info(Message, Args) ->
case application:get_env(elvis_core, verbose) of
Expand All @@ -188,6 +194,7 @@ parse_colors(Message) ->
"green-bold" => "\e[1;32m",
"white" => "\e[0;37m",
"white-bold" => "\e[1;37m",
"magenta" => "\e[1;35m",
"reset" => "\e[0m"},
Opts = [global, {return, list}],
case application:get_env(elvis_core, output_format, colors) of
Expand Down

0 comments on commit 1cfbd98

Please sign in to comment.