Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue warnings on empty folders #169

Merged
merged 1 commit into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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