Skip to content

Commit

Permalink
Fetch from elvis.config if not found in application:
Browse files Browse the repository at this point in the history
  • Loading branch information
paulo-ferraz-oliveira committed Jul 6, 2021
1 parent 86da503 commit 4a1a9bf
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/elvis_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

-export([ from_rebar/1
, from_file/1
, from_application_or_config/2
, validate/1
, normalize/1
%% Geters
Expand Down Expand Up @@ -52,6 +53,9 @@ from_file(Path, Key, Default) ->
throw(Reason)
end.

-spec from_application_or_config(atom(), term()) -> term().
from_application_or_config(Key, Default) ->
application:get_env(elvis_core, Key, from_file("elvis.config", Key, Default)).

-spec load(atom(), term(), term()) -> configs().
load(Key, ElvisConfig, Default) ->
Expand Down
2 changes: 1 addition & 1 deletion src/elvis_core.erl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ rock_this(Path, Config) ->
-spec do_parallel_rock(elvis_config:config())
-> ok | {fail, [elvis_result:file() | elvis_result:rule()]}.
do_parallel_rock(Config0) ->
Parallel = application:get_env(elvis_core, parallel, 1),
Parallel = elvis_config:from_application_or_config(parallel, 1),
Config = elvis_config:resolve_files(Config0),
Files = elvis_config:files(Config),

Expand Down
2 changes: 1 addition & 1 deletion src/elvis_result.erl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ get_line_num(#{line_num := LineNum}) -> LineNum.

-spec print_results(file() | [elvis_warn()]) -> ok.
print_results(Results) ->
Format = application:get_env(elvis_core, output_format, colors),
Format = elvis_config:from_application_or_config(output_format, colors),
print(Format, Results).

-spec print(plain | colors | parsable, [file()] | file()) -> ok.
Expand Down
12 changes: 6 additions & 6 deletions src/elvis_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,15 @@ warn_prn(Message, Args) ->

-spec print_info(string(), [term()]) -> ok.
print_info(Message, Args) ->
case application:get_env(elvis_core, verbose) of
{ok, true} -> print(Message, Args);
_ -> ok
case elvis_config:from_application_or_config(verbose, false) of
true -> print(Message, Args);
false -> ok
end.

-spec print(string(), [term()]) -> ok.
print(Message, Args) ->
case application:get_env(elvis_core, no_output) of
{ok, true} -> ok;
case elvis_config:from_application_or_config(no_output, false) of
true -> ok;
_ ->
Output = io_lib:format(Message, Args),
EscapedOutput = escape_format_str(Output),
Expand All @@ -197,7 +197,7 @@ parse_colors(Message) ->
"magenta" => "\e[1;35m",
"reset" => "\e[0m"},
Opts = [global, {return, list}],
case application:get_env(elvis_core, output_format, colors) of
case elvis_config:from_application_or_config(output_format, colors) of
P when P =:= plain orelse
P =:= parsable ->
re:replace(Message, "{{.*?}}", "", Opts);
Expand Down

0 comments on commit 4a1a9bf

Please sign in to comment.